## Longitudinal data
data_sum <- loadlongitudinaldata(dataset = "DATA_Adults_G1G29.csv", rm_generation1 = 1,rm_generation2 = 7,rm_generation3 = 29)
## Phenotyping steps
data_G0 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G1")
data_G7 <- loadfitnessdata(dataset = "Selection_Phenotypage_G0_G7_G8.csv", generation = "G7")
data_G29 <- loadfitnessdata(dataset =
"PERFORMANCE_Comptage_adultes_G13G14G15G16G17G18G19G20G21G22G23G24G25G26G27G28G29.csv",
generation = "29")
head(data_sum)
## Line Fruit_s Generation Phase N Nb_adults sd fitness
## 1 CE1 Cherry 2 first_prepool 20 9.15000 6.123939 -0.7819784
## 2 CE1 Cherry 3 first_prepool 10 15.30000 7.631077 -0.2678794
## 3 CE1 Cherry 4 first_prepool 8 15.00000 7.782765 -0.2876821
## 4 CE1 Cherry 5 first_prepool 6 14.50000 6.284903 -0.3215836
## 5 CE2 Cherry 2 first_prepool 20 7.75000 7.758696 -0.9480394
## 6 CE2 Cherry 3 first_prepool 7 14.42857 8.303757 -0.3265219
## se_fitness
## 1 0.1496562
## 2 0.1577228
## 3 0.1834415
## 4 0.1769518
## 5 0.2238577
## 6 0.2175215
head(data_G0)
## Treatment Line Fruit_s Nb_eggs Nb_adults SA Emergence_rate
## 993 Cherry CE1 GF 76 6 0 0.07894737
## 994 Cherry CE1 GF 89 17 0 0.19101124
## 995 Cherry CE1 GF 57 12 0 0.21052632
## 996 Cherry CE1 GF 172 24 0 0.13953488
## 997 Cherry CE1 GF 173 33 0 0.19075145
## 998 Cherry CE1 GF 91 18 0 0.19780220
head(data_G7)
## Treatment Line Fruit_s Nb_eggs Nb_adults SA Emergence_rate
## 3 Strawberry CR4 Cranberry 152 68 0 0.4473684
## 4 Cranberry CR4 Cranberry 246 25 1 0.1016260
## 5 Cherry CR4 Cranberry 238 29 0 0.1218487
## 6 Cherry CR4 Cranberry 166 23 0 0.1385542
## 8 Cranberry FR3 Strawberry 204 5 0 0.0245098
## 9 Strawberry FR3 Strawberry 124 45 1 0.3629032
head(data_G29)
## Treatment Line Fruit_s Nb_eggs Nb_adults SA Emergence_rate
## 5392 Strawberry CEA Cherry 196 16 0 0.08163265
## 5393 Strawberry CEA Cherry 192 30 0 0.15625000
## 5394 Strawberry CEA Cherry 160 17 0 0.10625000
## 5395 Strawberry CEA Cherry 106 9 0 0.08490566
## 5396 Strawberry CEA Cherry 119 14 0 0.11764706
## 5397 Strawberry CEA Cherry 204 24 0 0.11764706
dim(data_G29)
## [1] 990 7
## Add line variable
levels(data_G0$Line) <- rep("Anc", nlevels(data_G0$Line))
## Combine datsets
data <- rbind(data_G0, data_G7, data_G29)
data <- data.frame(Generation = c(rep("0", nrow(data_G0)), rep("7", nrow(data_G7)), rep("29", nrow(data_G29))), data, Obs= as.factor(1:nrow(data)))
head(data)
## Generation Treatment Line Fruit_s Nb_eggs Nb_adults SA Emergence_rate Obs
## 993 0 Cherry Anc GF 76 6 0 0.07894737 1
## 994 0 Cherry Anc GF 89 17 0 0.19101124 2
## 995 0 Cherry Anc GF 57 12 0 0.21052632 3
## 996 0 Cherry Anc GF 172 24 0 0.13953488 4
## 997 0 Cherry Anc GF 173 33 0 0.19075145 5
## 998 0 Cherry Anc GF 91 18 0 0.19780220 6
## New variable for analyses
data$Generation_Fruit_s_Treatment <- as.factor(paste(data$Generation, data$Fruit_s, data$Treatment, sep="_"))
data$Line_Treatment <- as.factor(paste(data$Line, data$Treatment, sep="_"))
data$Treatmentrel <- relevel(data$Treatment, ref="Strawberry")
mfitness <- MASS::glm.nb(Nb_adults ~ Treatment, data=data)
summary(mfitness)
##
## Call:
## MASS::glm.nb(formula = Nb_adults ~ Treatment, data = data, init.theta = 1.909520807,
## link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.2900 -0.8197 -0.1146 0.4139 2.7450
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.39580 0.03163 107.365 <2e-16 ***
## TreatmentCranberry -0.05073 0.04470 -1.135 0.256
## TreatmentStrawberry 0.02466 0.04471 0.552 0.581
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(1.9095) family taken to be 1)
##
## Null deviance: 1892.5 on 1673 degrees of freedom
## Residual deviance: 1889.5 on 1671 degrees of freedom
## AIC: 14468
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 1.9095
## Std. Err.: 0.0698
##
## 2 x log-likelihood: -14460.0940
pr1 <- profile(mfitness, alpha = 0.1)
MASS:::plot.profile(pr1)
### Fitness
mfitness <- MASS::glm.nb(Nb_adults ~ -1 + Treatment + Line:Treatment, data=data)
summary(mfitness)
##
## Call:
## MASS::glm.nb(formula = Nb_adults ~ -1 + Treatment + Line:Treatment,
## data = data, init.theta = 2.366102685, link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.8419 -0.7673 -0.0402 0.4835 3.7740
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## TreatmentCherry 3.21848 0.06802 47.318 < 2e-16 ***
## TreatmentCranberry 3.26385 0.06789 48.077 < 2e-16 ***
## TreatmentStrawberry 3.35446 0.06764 49.590 < 2e-16 ***
## TreatmentCherry:LineCE1 -0.27404 0.22837 -1.200 0.230153
## TreatmentCranberry:LineCE1 -0.91247 0.26333 -3.465 0.000530 ***
## TreatmentStrawberry:LineCE1 0.09553 0.24774 0.386 0.699777
## TreatmentCherry:LineCE2 -0.56172 0.35753 -1.571 0.116160
## TreatmentCranberry:LineCE2 -0.20358 0.40139 -0.507 0.612024
## TreatmentStrawberry:LineCE2 0.22906 0.47936 0.478 0.632752
## TreatmentCherry:LineCE3 0.18528 0.19923 0.930 0.352387
## TreatmentCranberry:LineCE3 -0.11040 0.20830 -0.530 0.596097
## TreatmentStrawberry:LineCE3 -0.01404 0.19953 -0.070 0.943891
## TreatmentCherry:LineCE4 0.12791 0.31015 0.412 0.680033
## TreatmentCranberry:LineCE4 0.46905 0.30646 1.531 0.125891
## TreatmentStrawberry:LineCE4 0.58713 0.33925 1.731 0.083510 .
## TreatmentCherry:LineCR1 0.63167 0.66973 0.943 0.345592
## TreatmentCranberry:LineCR1 0.26984 0.34288 0.787 0.431298
## TreatmentStrawberry:LineCR1 -0.46408 0.49363 -0.940 0.347144
## TreatmentCherry:LineCR2 0.37884 0.34225 1.107 0.268337
## TreatmentCranberry:LineCR2 -0.10685 0.28660 -0.373 0.709287
## TreatmentStrawberry:LineCR2 0.23598 0.34224 0.690 0.490496
## TreatmentCherry:LineCR3 -0.62165 0.17548 -3.543 0.000396 ***
## TreatmentCranberry:LineCR3 0.05810 0.16264 0.357 0.720928
## TreatmentStrawberry:LineCR3 0.10658 0.16516 0.645 0.518711
## TreatmentCherry:LineCR4 0.20904 0.30927 0.676 0.499096
## TreatmentCranberry:LineCR4 0.35156 0.28201 1.247 0.212540
## TreatmentStrawberry:LineCR4 0.52917 0.30532 1.733 0.083064 .
## TreatmentCherry:LineCR5 0.53338 0.30635 1.741 0.081667 .
## TreatmentCranberry:LineCR5 0.18840 0.26365 0.715 0.474855
## TreatmentStrawberry:LineCR5 0.10344 0.34367 0.301 0.763430
## TreatmentCherry:LineFR1 0.34257 0.14022 2.443 0.014561 *
## TreatmentCranberry:LineFR1 0.35172 0.14181 2.480 0.013131 *
## TreatmentStrawberry:LineFR1 0.33051 0.13626 2.426 0.015285 *
## TreatmentCherry:LineFR2 0.35574 0.28238 1.260 0.207744
## TreatmentCranberry:LineFR2 -0.16526 0.28734 -0.575 0.565206
## TreatmentStrawberry:LineFR2 0.09023 0.28343 0.318 0.750229
## TreatmentCherry:LineFR3 0.57926 0.30600 1.893 0.058361 .
## TreatmentCranberry:LineFR3 0.17014 0.30917 0.550 0.582113
## TreatmentStrawberry:LineFR3 0.13336 0.26329 0.507 0.612498
## TreatmentCherry:LineFR4 0.72973 0.16699 4.370 1.24e-05 ***
## TreatmentCranberry:LineFR4 0.36284 0.17617 2.060 0.039432 *
## TreatmentStrawberry:LineFR4 0.58063 0.17071 3.401 0.000671 ***
## TreatmentCherry:LineFR5 0.30788 0.67578 0.456 0.648677
## TreatmentCranberry:LineFR5 0.39971 0.67297 0.594 0.552542
## TreatmentStrawberry:LineFR5 0.18650 0.47999 0.389 0.697600
## TreatmentCherry:LineCEA 0.14767 0.14094 1.048 0.294766
## TreatmentCranberry:LineCEA -0.21774 0.14241 -1.529 0.126279
## TreatmentStrawberry:LineCEA 0.01971 0.14073 0.140 0.888596
## TreatmentCherry:LineCEB 0.25038 0.14054 1.781 0.074831 .
## TreatmentCranberry:LineCEB -0.59200 0.14492 -4.085 4.41e-05 ***
## TreatmentStrawberry:LineCEB -0.15851 0.14152 -1.120 0.262699
## TreatmentCherry:LineCEC 0.35854 0.14017 2.558 0.010528 *
## TreatmentCranberry:LineCEC -0.20671 0.14235 -1.452 0.146475
## TreatmentStrawberry:LineCEC 0.21131 0.14002 1.509 0.131258
## TreatmentCherry:LineCRA 0.32538 0.14028 2.320 0.020366 *
## TreatmentCranberry:LineCRA -0.14885 0.14204 -1.048 0.294660
## TreatmentStrawberry:LineCRA -0.29731 0.14224 -2.090 0.036591 *
## TreatmentCherry:LineCRB 0.16930 0.14086 1.202 0.229393
## TreatmentCranberry:LineCRB 0.29720 0.14016 2.120 0.033966 *
## TreatmentStrawberry:LineCRB -0.24539 0.14196 -1.729 0.083870 .
## TreatmentCherry:LineCRC 0.08474 0.14121 0.600 0.548430
## TreatmentCranberry:LineCRC 0.02704 0.14120 0.191 0.848148
## TreatmentStrawberry:LineCRC -0.28951 0.14219 -2.036 0.041748 *
## TreatmentCherry:LineCRD 0.54736 0.13959 3.921 8.81e-05 ***
## TreatmentCranberry:LineCRD -0.15628 0.14208 -1.100 0.271367
## TreatmentStrawberry:LineCRD -1.02555 0.14802 -6.928 4.26e-12 ***
## TreatmentCherry:LineCRE -0.10496 0.14211 -0.739 0.460165
## TreatmentCranberry:LineCRE 0.72513 0.13897 5.218 1.81e-07 ***
## TreatmentStrawberry:LineCRE -0.16810 0.14157 -1.187 0.235050
## TreatmentCherry:LineFRA -0.50599 0.14466 -3.498 0.000469 ***
## TreatmentCranberry:LineFRA -0.25159 0.14260 -1.764 0.077692 .
## TreatmentStrawberry:LineFRA 0.15709 0.14021 1.120 0.262542
## TreatmentCherry:LineFRB 0.19377 0.14076 1.377 0.168632
## TreatmentCranberry:LineFRB 0.04304 0.14113 0.305 0.760404
## TreatmentStrawberry:LineFRB 0.56023 0.13903 4.030 5.59e-05 ***
## TreatmentCherry:LineFRC 0.32152 0.14029 2.292 0.021918 *
## TreatmentCranberry:LineFRC 0.52110 0.13948 3.736 0.000187 ***
## TreatmentStrawberry:LineFRC 0.36641 0.13954 2.626 0.008643 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(2.3661) family taken to be 1)
##
## Null deviance: 97071.5 on 1674 degrees of freedom
## Residual deviance: 1897.6 on 1596 degrees of freedom
## AIC: 14287
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 2.3661
## Std. Err.: 0.0906
##
## 2 x log-likelihood: -14129.0600
CIfitness <- confint(mfitness)
pr1 <- profile(mfitness, alpha = 0.1)
# pdf(file="figures/Profile.pdf")
# MASS:::plot.profile(pr1)
# dev.off()
###
### Fecundity
###
mfecundity <- MASS::glm.nb(Nb_eggs ~ -1+Treatment+Line:Treatment, data=data)
summary(mfecundity)
##
## Call:
## MASS::glm.nb(formula = Nb_eggs ~ -1 + Treatment + Line:Treatment,
## data = data, init.theta = 8.2113987, link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -5.7949 -0.6864 -0.0232 0.5593 3.0051
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## TreatmentCherry 5.00723 0.03584 139.699 < 2e-16 ***
## TreatmentCranberry 4.81096 0.03604 133.472 < 2e-16 ***
## TreatmentStrawberry 4.68065 0.03620 129.294 < 2e-16 ***
## TreatmentCherry:LineCE1 0.21744 0.11833 1.838 0.066115 .
## TreatmentCranberry:LineCE1 0.39304 0.13118 2.996 0.002734 **
## TreatmentStrawberry:LineCE1 0.48342 0.13133 3.681 0.000232 ***
## TreatmentCherry:LineCE2 0.55345 0.18081 3.061 0.002206 **
## TreatmentCranberry:LineCE2 0.43255 0.20893 2.070 0.038430 *
## TreatmentStrawberry:LineCE2 0.27518 0.25636 1.073 0.283097
## TreatmentCherry:LineCE3 0.18914 0.10525 1.797 0.072338 .
## TreatmentCranberry:LineCE3 0.33605 0.10924 3.076 0.002096 **
## TreatmentStrawberry:LineCE3 0.43781 0.10554 4.148 3.35e-05 ***
## TreatmentCherry:LineCE4 0.29906 0.16320 1.832 0.066879 .
## TreatmentCranberry:LineCE4 0.27910 0.16397 1.702 0.088737 .
## TreatmentStrawberry:LineCE4 0.69925 0.18141 3.855 0.000116 ***
## TreatmentCherry:LineCR1 -0.27103 0.36310 -0.746 0.455399
## TreatmentCranberry:LineCR1 0.07562 0.18339 0.412 0.680090
## TreatmentStrawberry:LineCR1 0.23568 0.25664 0.918 0.358456
## TreatmentCherry:LineCR2 0.17033 0.18205 0.936 0.349452
## TreatmentCranberry:LineCR2 0.24740 0.15052 1.644 0.100242
## TreatmentStrawberry:LineCR2 0.19455 0.18348 1.060 0.288993
## TreatmentCherry:LineCR3 0.28872 0.08921 3.236 0.001210 **
## TreatmentCranberry:LineCR3 0.44703 0.08571 5.216 1.83e-07 ***
## TreatmentStrawberry:LineCR3 0.34126 0.08792 3.882 0.000104 ***
## TreatmentCherry:LineCR4 0.16779 0.16362 1.025 0.305142
## TreatmentCranberry:LineCR4 0.48150 0.14978 3.215 0.001306 **
## TreatmentStrawberry:LineCR4 0.32330 0.16434 1.967 0.049161 *
## TreatmentCherry:LineCR5 0.08652 0.16391 0.528 0.597611
## TreatmentCranberry:LineCR5 0.38990 0.13959 2.793 0.005218 **
## TreatmentStrawberry:LineCR5 0.25562 0.18317 1.396 0.162852
## TreatmentCherry:LineFR1 0.28390 0.07424 3.824 0.000131 ***
## TreatmentCranberry:LineFR1 0.37275 0.07544 4.941 7.78e-07 ***
## TreatmentStrawberry:LineFR1 0.51854 0.07272 7.130 1.00e-12 ***
## TreatmentCherry:LineFR2 0.05431 0.15046 0.361 0.718126
## TreatmentCranberry:LineFR2 0.52657 0.14966 3.519 0.000434 ***
## TreatmentStrawberry:LineFR2 0.27283 0.15094 1.807 0.070687 .
## TreatmentCherry:LineFR3 0.05916 0.16402 0.361 0.718350
## TreatmentCranberry:LineFR3 0.31419 0.16384 1.918 0.055159 .
## TreatmentStrawberry:LineFR3 0.30784 0.14029 2.194 0.028215 *
## TreatmentCherry:LineFR4 0.15635 0.08942 1.749 0.080364 .
## TreatmentCranberry:LineFR4 0.56758 0.09346 6.073 1.25e-09 ***
## TreatmentStrawberry:LineFR4 0.50984 0.09157 5.568 2.58e-08 ***
## TreatmentCherry:LineFR5 -0.04438 0.36064 -0.123 0.902049
## TreatmentCranberry:LineFR5 0.93843 0.35534 2.641 0.008268 **
## TreatmentStrawberry:LineFR5 0.67594 0.25409 2.660 0.007808 **
## TreatmentCherry:LineCEA -0.33378 0.07520 -4.438 9.06e-06 ***
## TreatmentCranberry:LineCEA 0.05785 0.07493 0.772 0.440078
## TreatmentStrawberry:LineCEA 0.25933 0.07489 3.463 0.000535 ***
## TreatmentCherry:LineCEB -0.38291 0.07531 -5.085 3.68e-07 ***
## TreatmentCranberry:LineCEB -0.08653 0.07520 -1.151 0.249844
## TreatmentStrawberry:LineCEB 0.14071 0.07509 1.874 0.060950 .
## TreatmentCherry:LineCEC -0.37932 0.07530 -5.038 4.72e-07 ***
## TreatmentCranberry:LineCEC 0.06855 0.07491 0.915 0.360163
## TreatmentStrawberry:LineCEC 0.18483 0.07501 2.464 0.013739 *
## TreatmentCherry:LineCRA -0.31070 0.07516 -4.134 3.56e-05 ***
## TreatmentCranberry:LineCRA -0.15067 0.07533 -2.000 0.045469 *
## TreatmentStrawberry:LineCRA 0.16825 0.07504 2.242 0.024953 *
## TreatmentCherry:LineCRB -0.37347 0.07529 -4.961 7.02e-07 ***
## TreatmentCranberry:LineCRB 0.10950 0.07485 1.463 0.143450
## TreatmentStrawberry:LineCRB 0.19988 0.07499 2.666 0.007687 **
## TreatmentCherry:LineCRC -0.24420 0.07503 -3.255 0.001134 **
## TreatmentCranberry:LineCRC -0.07155 0.07517 -0.952 0.341128
## TreatmentStrawberry:LineCRC 0.18174 0.07502 2.423 0.015406 *
## TreatmentCherry:LineCRD -0.26201 0.07506 -3.491 0.000482 ***
## TreatmentCranberry:LineCRD 0.10853 0.07485 1.450 0.147050
## TreatmentStrawberry:LineCRD -0.03786 0.07544 -0.502 0.615747
## TreatmentCherry:LineCRE -0.33783 0.07521 -4.492 7.06e-06 ***
## TreatmentCranberry:LineCRE 0.01307 0.07501 0.174 0.861633
## TreatmentStrawberry:LineCRE 0.18226 0.07502 2.430 0.015116 *
## TreatmentCherry:LineFRA -0.34947 0.07524 -4.645 3.40e-06 ***
## TreatmentCranberry:LineFRA -0.06923 0.07516 -0.921 0.357045
## TreatmentStrawberry:LineFRA 0.12446 0.07512 1.657 0.097540 .
## TreatmentCherry:LineFRB -0.49820 0.07557 -6.592 4.33e-11 ***
## TreatmentCranberry:LineFRB -0.20679 0.07545 -2.741 0.006127 **
## TreatmentStrawberry:LineFRB 0.14232 0.07509 1.895 0.058043 .
## TreatmentCherry:LineFRC -0.58678 0.07580 -7.742 9.82e-15 ***
## TreatmentCranberry:LineFRC -0.10565 0.07523 -1.404 0.160247
## TreatmentStrawberry:LineFRC 0.21520 0.07496 2.871 0.004094 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(8.2114) family taken to be 1)
##
## Null deviance: 889732.5 on 1674 degrees of freedom
## Residual deviance: 1730.1 on 1596 degrees of freedom
## AIC: 17660
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 8.211
## Std. Err.: 0.301
##
## 2 x log-likelihood: -17501.650
CIfecundity <- confint(mfecundity)
###
### Egg-to-adult viability
###
## 4 tubes with more adults than eggs
sum(data$Nb_adults>data$Nb_eggs)
## [1] 4
## Number of adults=number of eggs
data$Nb_eggs[data$Nb_adults>data$Nb_eggs] <- data$Nb_adults[data$Nb_adults>data$Nb_eggs]
## Fit model
megg_to_ad <- glm(cbind(Nb_adults, Nb_eggs) ~ -1+Treatment+Line:Treatment, data=data, family="binomial")
summary(megg_to_ad)
##
## Call:
## glm(formula = cbind(Nb_adults, Nb_eggs) ~ -1 + Treatment + Line:Treatment,
## family = "binomial", data = data)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -11.2550 -2.2309 0.0851 2.0910 13.2204
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## TreatmentCherry -1.788754 0.021611 -82.769 < 2e-16 ***
## TreatmentCranberry -1.547115 0.021536 -71.838 < 2e-16 ***
## TreatmentStrawberry -1.326194 0.021024 -63.080 < 2e-16 ***
## TreatmentCherry:LineCE1 -0.494166 0.079164 -6.242 4.31e-10 ***
## TreatmentCranberry:LineCE1 -1.305517 0.114258 -11.426 < 2e-16 ***
## TreatmentStrawberry:LineCE1 -0.387890 0.071590 -5.418 6.02e-08 ***
## TreatmentCherry:LineCE2 -1.115171 0.137737 -8.096 5.66e-16 ***
## TreatmentCranberry:LineCE2 -0.636123 0.133602 -4.761 1.92e-06 ***
## TreatmentStrawberry:LineCE2 -0.046115 0.133611 -0.345 0.729990
## TreatmentCherry:LineCE3 -0.003858 0.058741 -0.066 0.947636
## TreatmentCranberry:LineCE3 -0.446447 0.067136 -6.650 2.93e-11 ***
## TreatmentStrawberry:LineCE3 -0.451848 0.060226 -7.503 6.26e-14 ***
## TreatmentCherry:LineCE4 -0.171143 0.092203 -1.856 0.063432 .
## TreatmentCranberry:LineCE4 0.189949 0.080499 2.360 0.018292 *
## TreatmentStrawberry:LineCE4 -0.112122 0.080302 -1.396 0.162639
## TreatmentCherry:LineCR1 0.902703 0.174687 5.168 2.37e-07 ***
## TreatmentCranberry:LineCR1 0.194219 0.098234 1.977 0.048029 *
## TreatmentStrawberry:LineCR1 -0.699759 0.178558 -3.919 8.89e-05 ***
## TreatmentCherry:LineCR2 0.208505 0.093417 2.232 0.025617 *
## TreatmentCranberry:LineCR2 -0.354251 0.092819 -3.817 0.000135 ***
## TreatmentStrawberry:LineCR2 0.041436 0.096161 0.431 0.666543
## TreatmentCherry:LineCR3 -0.910368 0.068209 -13.347 < 2e-16 ***
## TreatmentCranberry:LineCR3 -0.388928 0.049294 -7.890 3.02e-15 ***
## TreatmentStrawberry:LineCR3 -0.234674 0.048389 -4.850 1.24e-06 ***
## TreatmentCherry:LineCR4 0.041249 0.089954 0.459 0.646551
## TreatmentCranberry:LineCR4 -0.129940 0.076068 -1.708 0.087598 .
## TreatmentStrawberry:LineCR4 0.205871 0.076808 2.680 0.007355 **
## TreatmentCherry:LineCR5 0.446858 0.079930 5.591 2.26e-08 ***
## TreatmentCranberry:LineCR5 -0.201495 0.076001 -2.651 0.008020 **
## TreatmentStrawberry:LineCR5 -0.152185 0.100555 -1.513 0.130167
## TreatmentCherry:LineFR1 0.058675 0.039773 1.475 0.140147
## TreatmentCranberry:LineFR1 -0.021037 0.039810 -0.528 0.597192
## TreatmentStrawberry:LineFR1 -0.188028 0.037401 -5.027 4.97e-07 ***
## TreatmentCherry:LineFR2 0.301431 0.078714 3.829 0.000128 ***
## TreatmentCranberry:LineFR2 -0.691834 0.093722 -7.382 1.56e-13 ***
## TreatmentStrawberry:LineFR2 -0.197779 0.083186 -2.378 0.017428 *
## TreatmentCherry:LineFR3 0.520102 0.078819 6.599 4.15e-11 ***
## TreatmentCranberry:LineFR3 -0.144052 0.090025 -1.600 0.109570
## TreatmentStrawberry:LineFR3 -0.174482 0.076043 -2.295 0.021761 *
## TreatmentCherry:LineFR4 0.573374 0.042230 13.577 < 2e-16 ***
## TreatmentCranberry:LineFR4 -0.204735 0.047960 -4.269 1.96e-05 ***
## TreatmentStrawberry:LineFR4 0.070797 0.042863 1.652 0.098590 .
## TreatmentCherry:LineFR5 0.352270 0.192020 1.835 0.066573 .
## TreatmentCranberry:LineFR5 -0.538716 0.171142 -3.148 0.001645 **
## TreatmentStrawberry:LineFR5 -0.489433 0.131504 -3.722 0.000198 ***
## TreatmentCherry:LineCEA 0.481448 0.043922 10.961 < 2e-16 ***
## TreatmentCranberry:LineCEA -0.275592 0.048007 -5.741 9.43e-09 ***
## TreatmentStrawberry:LineCEA -0.239612 0.042686 -5.613 1.98e-08 ***
## TreatmentCherry:LineCEB 0.633291 0.042808 14.794 < 2e-16 ***
## TreatmentCranberry:LineCEB -0.505472 0.055352 -9.132 < 2e-16 ***
## TreatmentStrawberry:LineCEB -0.299214 0.045550 -6.569 5.07e-11 ***
## TreatmentCherry:LineCEC 0.737860 0.041531 17.766 < 2e-16 ***
## TreatmentCranberry:LineCEC -0.275258 0.047797 -5.759 8.47e-09 ***
## TreatmentStrawberry:LineCEC 0.026482 0.040515 0.654 0.513343
## TreatmentCherry:LineCRA 0.636074 0.041649 15.272 < 2e-16 ***
## TreatmentCranberry:LineCRA 0.001821 0.047524 0.038 0.969433
## TreatmentStrawberry:LineCRA -0.465566 0.047651 -9.770 < 2e-16 ***
## TreatmentCherry:LineCRB 0.542770 0.043785 12.396 < 2e-16 ***
## TreatmentCranberry:LineCRB 0.187694 0.040669 4.615 3.93e-06 ***
## TreatmentStrawberry:LineCRB -0.445272 0.046725 -9.530 < 2e-16 ***
## TreatmentCherry:LineCRC 0.328942 0.044466 7.398 1.39e-13 ***
## TreatmentCranberry:LineCRC 0.098592 0.044676 2.207 0.027328 *
## TreatmentStrawberry:LineCRC -0.471252 0.047486 -9.924 < 2e-16 ***
## TreatmentCherry:LineCRD 0.809372 0.039095 20.703 < 2e-16 ***
## TreatmentCranberry:LineCRD -0.264808 0.046878 -5.649 1.62e-08 ***
## TreatmentStrawberry:LineCRD -0.987691 0.063323 -15.598 < 2e-16 ***
## TreatmentCherry:LineCRE 0.232873 0.047551 4.897 9.72e-07 ***
## TreatmentCranberry:LineCRE 0.712061 0.036727 19.388 < 2e-16 ***
## TreatmentStrawberry:LineCRE -0.350362 0.045574 -7.688 1.50e-14 ***
## TreatmentCherry:LineFRA -0.156524 0.054733 -2.860 0.004239 **
## TreatmentCranberry:LineFRA -0.182362 0.048928 -3.727 0.000194 ***
## TreatmentStrawberry:LineFRA 0.032626 0.041352 0.789 0.430124
## TreatmentCherry:LineFRB 0.691975 0.043965 15.739 < 2e-16 ***
## TreatmentCranberry:LineFRB 0.249832 0.044927 5.561 2.69e-08 ***
## TreatmentStrawberry:LineFRB 0.407777 0.037045 11.008 < 2e-16 ***
## TreatmentCherry:LineFRC 0.908301 0.042838 21.203 < 2e-16 ***
## TreatmentCranberry:LineFRC 0.626745 0.039018 16.063 < 2e-16 ***
## TreatmentStrawberry:LineFRC 0.151208 0.038709 3.906 9.37e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 142163 on 1674 degrees of freedom
## Residual deviance: 17859 on 1596 degrees of freedom
## AIC: 25827
##
## Number of Fisher Scoring iterations: 5
CImegg_to_ad <- confint(megg_to_ad)
#######
####### Build data_logchange dataset
#######
## Extract all CIs
## Check that the coef are in the same order
identical(names(coef(mfitness)), names(coef(mfecundity)))
## [1] TRUE
identical(names(coef(mfitness)), names(coef(megg_to_ad)))
## [1] TRUE
data_logchange <- data.frame(logchange=coef(mfitness),
lowCIlogfitnesschange=CIfitness[, 1],
upCIlogfitnesschange=CIfitness[, 2],
logfecundchange=coef(mfecundity),
lowCIlogfecundchange=CIfecundity[, 1],
upCIlogfecundchange=CIfecundity[, 2],
logeggtoadchange=coef(megg_to_ad),
lowCIlogeggtoadchange=CImegg_to_ad[, 1],
upCIlogeggtoadchange=CImegg_to_ad[, 2])
head(data_logchange)
## logchange lowCIlogfitnesschange
## TreatmentCherry 3.21847574 3.0875555
## TreatmentCranberry 3.26384919 3.1331965
## TreatmentStrawberry 3.35445512 3.2243029
## TreatmentCherry:LineCE1 -0.27403677 -0.7021017
## TreatmentCranberry:LineCE1 -0.91247393 -1.4069620
## TreatmentStrawberry:LineCE1 0.09553243 -0.3637574
## upCIlogfitnesschange logfecundchange
## TreatmentCherry 3.3543047 5.0072295
## TreatmentCranberry 3.3994333 4.8109641
## TreatmentStrawberry 3.4895811 4.6806486
## TreatmentCherry:LineCE1 0.1969999 0.2174413
## TreatmentCranberry:LineCE1 -0.3690326 0.3930426
## TreatmentStrawberry:LineCE1 0.6127366 0.4834228
## lowCIlogfecundchange upCIlogfecundchange
## TreatmentCherry 4.937707676 5.0782276
## TreatmentCranberry 4.741037413 4.8823484
## TreatmentStrawberry 4.610407277 4.7523331
## TreatmentCherry:LineCE1 -0.008054728 0.4563722
## TreatmentCranberry:LineCE1 0.144087552 0.6591387
## TreatmentStrawberry:LineCE1 0.234153348 0.7497917
## logeggtoadchange lowCIlogeggtoadchange
## TreatmentCherry -1.7887538 -1.8313270
## TreatmentCranberry -1.5471149 -1.5895200
## TreatmentStrawberry -1.3261935 -1.3675662
## TreatmentCherry:LineCE1 -0.4941655 -0.6522000
## TreatmentCranberry:LineCE1 -1.3055165 -1.5366802
## TreatmentStrawberry:LineCE1 -0.3878904 -0.5301533
## upCIlogeggtoadchange
## TreatmentCherry -1.7466080
## TreatmentCranberry -1.5050959
## TreatmentStrawberry -1.2851499
## TreatmentCherry:LineCE1 -0.3417120
## TreatmentCranberry:LineCE1 -1.0882241
## TreatmentStrawberry:LineCE1 -0.2494137
## Remove estimates from ancestral population
data_logchange <- data_logchange[4:nrow(data_logchange), ]
## Extract information regarding line, selective and test media
rowname <- strsplit(rownames(data_logchange), split=":")
Treatment <- as.factor(gsub("Treatment", "", lapply(rowname, `[[`, 1)))
Generation <- Line <- as.factor(gsub("Line", "", lapply(rowname, `[[`, 2)))
## Change Fruit_s levels
Fruit_s <- as.factor(substr(Line, 1, 2))
levels(Fruit_s) <- levels(Treatment)
## Change levels
levels(Generation) <- ifelse(is.na(as.numeric(substr(levels(Generation), 3, 3))), "29", "7")
## Combine data
data_info <- data.frame(Treatment, Line, Fruit_s, Generation)
data_info$Line_Treatement <- paste(data_info$Line, data_info$Treatment, sep="_")
# Add symp and allop
data_info$SA <- as.factor(ifelse(data_info$Treatment == data_info$Fruit_s , 1, 0))
data.frame(names(coef(mfitness))[4:length(coef(mfitness))], data_info)
## names.coef.mfitness...4.length.coef.mfitness... Treatment Line Fruit_s
## 1 TreatmentCherry:LineCE1 Cherry CE1 Cherry
## 2 TreatmentCranberry:LineCE1 Cranberry CE1 Cherry
## 3 TreatmentStrawberry:LineCE1 Strawberry CE1 Cherry
## 4 TreatmentCherry:LineCE2 Cherry CE2 Cherry
## 5 TreatmentCranberry:LineCE2 Cranberry CE2 Cherry
## 6 TreatmentStrawberry:LineCE2 Strawberry CE2 Cherry
## 7 TreatmentCherry:LineCE3 Cherry CE3 Cherry
## 8 TreatmentCranberry:LineCE3 Cranberry CE3 Cherry
## 9 TreatmentStrawberry:LineCE3 Strawberry CE3 Cherry
## 10 TreatmentCherry:LineCE4 Cherry CE4 Cherry
## 11 TreatmentCranberry:LineCE4 Cranberry CE4 Cherry
## 12 TreatmentStrawberry:LineCE4 Strawberry CE4 Cherry
## 13 TreatmentCherry:LineCR1 Cherry CR1 Cranberry
## 14 TreatmentCranberry:LineCR1 Cranberry CR1 Cranberry
## 15 TreatmentStrawberry:LineCR1 Strawberry CR1 Cranberry
## 16 TreatmentCherry:LineCR2 Cherry CR2 Cranberry
## 17 TreatmentCranberry:LineCR2 Cranberry CR2 Cranberry
## 18 TreatmentStrawberry:LineCR2 Strawberry CR2 Cranberry
## 19 TreatmentCherry:LineCR3 Cherry CR3 Cranberry
## 20 TreatmentCranberry:LineCR3 Cranberry CR3 Cranberry
## 21 TreatmentStrawberry:LineCR3 Strawberry CR3 Cranberry
## 22 TreatmentCherry:LineCR4 Cherry CR4 Cranberry
## 23 TreatmentCranberry:LineCR4 Cranberry CR4 Cranberry
## 24 TreatmentStrawberry:LineCR4 Strawberry CR4 Cranberry
## 25 TreatmentCherry:LineCR5 Cherry CR5 Cranberry
## 26 TreatmentCranberry:LineCR5 Cranberry CR5 Cranberry
## 27 TreatmentStrawberry:LineCR5 Strawberry CR5 Cranberry
## 28 TreatmentCherry:LineFR1 Cherry FR1 Strawberry
## 29 TreatmentCranberry:LineFR1 Cranberry FR1 Strawberry
## 30 TreatmentStrawberry:LineFR1 Strawberry FR1 Strawberry
## 31 TreatmentCherry:LineFR2 Cherry FR2 Strawberry
## 32 TreatmentCranberry:LineFR2 Cranberry FR2 Strawberry
## 33 TreatmentStrawberry:LineFR2 Strawberry FR2 Strawberry
## 34 TreatmentCherry:LineFR3 Cherry FR3 Strawberry
## 35 TreatmentCranberry:LineFR3 Cranberry FR3 Strawberry
## 36 TreatmentStrawberry:LineFR3 Strawberry FR3 Strawberry
## 37 TreatmentCherry:LineFR4 Cherry FR4 Strawberry
## 38 TreatmentCranberry:LineFR4 Cranberry FR4 Strawberry
## 39 TreatmentStrawberry:LineFR4 Strawberry FR4 Strawberry
## 40 TreatmentCherry:LineFR5 Cherry FR5 Strawberry
## 41 TreatmentCranberry:LineFR5 Cranberry FR5 Strawberry
## 42 TreatmentStrawberry:LineFR5 Strawberry FR5 Strawberry
## 43 TreatmentCherry:LineCEA Cherry CEA Cherry
## 44 TreatmentCranberry:LineCEA Cranberry CEA Cherry
## 45 TreatmentStrawberry:LineCEA Strawberry CEA Cherry
## 46 TreatmentCherry:LineCEB Cherry CEB Cherry
## 47 TreatmentCranberry:LineCEB Cranberry CEB Cherry
## 48 TreatmentStrawberry:LineCEB Strawberry CEB Cherry
## 49 TreatmentCherry:LineCEC Cherry CEC Cherry
## 50 TreatmentCranberry:LineCEC Cranberry CEC Cherry
## 51 TreatmentStrawberry:LineCEC Strawberry CEC Cherry
## 52 TreatmentCherry:LineCRA Cherry CRA Cranberry
## 53 TreatmentCranberry:LineCRA Cranberry CRA Cranberry
## 54 TreatmentStrawberry:LineCRA Strawberry CRA Cranberry
## 55 TreatmentCherry:LineCRB Cherry CRB Cranberry
## 56 TreatmentCranberry:LineCRB Cranberry CRB Cranberry
## 57 TreatmentStrawberry:LineCRB Strawberry CRB Cranberry
## 58 TreatmentCherry:LineCRC Cherry CRC Cranberry
## 59 TreatmentCranberry:LineCRC Cranberry CRC Cranberry
## 60 TreatmentStrawberry:LineCRC Strawberry CRC Cranberry
## 61 TreatmentCherry:LineCRD Cherry CRD Cranberry
## 62 TreatmentCranberry:LineCRD Cranberry CRD Cranberry
## 63 TreatmentStrawberry:LineCRD Strawberry CRD Cranberry
## 64 TreatmentCherry:LineCRE Cherry CRE Cranberry
## 65 TreatmentCranberry:LineCRE Cranberry CRE Cranberry
## 66 TreatmentStrawberry:LineCRE Strawberry CRE Cranberry
## 67 TreatmentCherry:LineFRA Cherry FRA Strawberry
## 68 TreatmentCranberry:LineFRA Cranberry FRA Strawberry
## 69 TreatmentStrawberry:LineFRA Strawberry FRA Strawberry
## 70 TreatmentCherry:LineFRB Cherry FRB Strawberry
## 71 TreatmentCranberry:LineFRB Cranberry FRB Strawberry
## 72 TreatmentStrawberry:LineFRB Strawberry FRB Strawberry
## 73 TreatmentCherry:LineFRC Cherry FRC Strawberry
## 74 TreatmentCranberry:LineFRC Cranberry FRC Strawberry
## 75 TreatmentStrawberry:LineFRC Strawberry FRC Strawberry
## Generation Line_Treatement SA
## 1 7 CE1_Cherry 1
## 2 7 CE1_Cranberry 0
## 3 7 CE1_Strawberry 0
## 4 7 CE2_Cherry 1
## 5 7 CE2_Cranberry 0
## 6 7 CE2_Strawberry 0
## 7 7 CE3_Cherry 1
## 8 7 CE3_Cranberry 0
## 9 7 CE3_Strawberry 0
## 10 7 CE4_Cherry 1
## 11 7 CE4_Cranberry 0
## 12 7 CE4_Strawberry 0
## 13 7 CR1_Cherry 0
## 14 7 CR1_Cranberry 1
## 15 7 CR1_Strawberry 0
## 16 7 CR2_Cherry 0
## 17 7 CR2_Cranberry 1
## 18 7 CR2_Strawberry 0
## 19 7 CR3_Cherry 0
## 20 7 CR3_Cranberry 1
## 21 7 CR3_Strawberry 0
## 22 7 CR4_Cherry 0
## 23 7 CR4_Cranberry 1
## 24 7 CR4_Strawberry 0
## 25 7 CR5_Cherry 0
## 26 7 CR5_Cranberry 1
## 27 7 CR5_Strawberry 0
## 28 7 FR1_Cherry 0
## 29 7 FR1_Cranberry 0
## 30 7 FR1_Strawberry 1
## 31 7 FR2_Cherry 0
## 32 7 FR2_Cranberry 0
## 33 7 FR2_Strawberry 1
## 34 7 FR3_Cherry 0
## 35 7 FR3_Cranberry 0
## 36 7 FR3_Strawberry 1
## 37 7 FR4_Cherry 0
## 38 7 FR4_Cranberry 0
## 39 7 FR4_Strawberry 1
## 40 7 FR5_Cherry 0
## 41 7 FR5_Cranberry 0
## 42 7 FR5_Strawberry 1
## 43 29 CEA_Cherry 1
## 44 29 CEA_Cranberry 0
## 45 29 CEA_Strawberry 0
## 46 29 CEB_Cherry 1
## 47 29 CEB_Cranberry 0
## 48 29 CEB_Strawberry 0
## 49 29 CEC_Cherry 1
## 50 29 CEC_Cranberry 0
## 51 29 CEC_Strawberry 0
## 52 29 CRA_Cherry 0
## 53 29 CRA_Cranberry 1
## 54 29 CRA_Strawberry 0
## 55 29 CRB_Cherry 0
## 56 29 CRB_Cranberry 1
## 57 29 CRB_Strawberry 0
## 58 29 CRC_Cherry 0
## 59 29 CRC_Cranberry 1
## 60 29 CRC_Strawberry 0
## 61 29 CRD_Cherry 0
## 62 29 CRD_Cranberry 1
## 63 29 CRD_Strawberry 0
## 64 29 CRE_Cherry 0
## 65 29 CRE_Cranberry 1
## 66 29 CRE_Strawberry 0
## 67 29 FRA_Cherry 0
## 68 29 FRA_Cranberry 0
## 69 29 FRA_Strawberry 1
## 70 29 FRB_Cherry 0
## 71 29 FRB_Cranberry 0
## 72 29 FRB_Strawberry 1
## 73 29 FRC_Cherry 0
## 74 29 FRC_Cranberry 0
## 75 29 FRC_Strawberry 1
## Compute sample size per line and test medium
sample_size <- aggregate(Nb_eggs~Line:Treatment, length, data=data[data$Generation!="0",])
sample_size$Line_Treatement <- paste(sample_size$Line, sample_size$Treatment, sep="_")
names(sample_size)[3] <- "N"
## Merge the three datasets
data_info <- merge(x=data_info, y=sample_size[, 3:4], by="Line_Treatement")
data_info$Line_Treatment <- paste0("Treatment", data_info$Treatment, ":Line", data_info$Line)
data_logchange$Line_Treatment <- rownames(data_logchange)
data_logchange <- merge(x=data_info, y=data_logchange, by = "Line_Treatment")[, -c(1, 2)]
head(data_logchange)
## Treatment Line Fruit_s Generation SA N logchange lowCIlogfitnesschange
## 1 Cherry CE1 Cherry 7 1 10 -0.2740368 -0.70210174
## 2 Cherry CE2 Cherry 7 1 4 -0.5617188 -1.21534852
## 3 Cherry CE3 Cherry 7 1 13 0.1852825 -0.18979611
## 4 Cherry CE4 Cherry 7 1 5 0.1279134 -0.43781493
## 5 Cherry CEA Cherry 29 1 30 0.1476700 -0.12317382
## 6 Cherry CEB Cherry 29 1 30 0.2503803 -0.01964191
## upCIlogfitnesschange logfecundchange lowCIlogfecundchange upCIlogfecundchange
## 1 0.1969999 0.2174413 -0.008054728 0.4563722
## 2 0.2019585 0.5534521 0.216090324 0.9271423
## 3 0.5938166 0.1891403 -0.012370462 0.4006261
## 4 0.7888315 0.2990560 -0.007390043 0.6339803
## 5 0.4301216 -0.3337778 -0.479544492 -0.1846294
## 6 0.5320919 -0.3829105 -0.528887054 -0.2335638
## logeggtoadchange lowCIlogeggtoadchange upCIlogeggtoadchange
## 1 -0.494165542 -0.6522000 -0.341712049
## 2 -1.115170967 -1.3960146 -0.855075837
## 3 -0.003857865 -0.1201706 0.110148034
## 4 -0.171142635 -0.3556475 0.006047628
## 5 0.481447806 0.3949970 0.567185941
## 6 0.633290781 0.5490961 0.716914363
#Formatting for plotting pairwise of fitness change
EC_Cran_Cher_G7<-formattingplotpair(data_logchange, "7", "Cherry", "Cranberry")
EC_Straw_Cran_G7<-formattingplotpair(data_logchange, "7", "Cranberry", "Strawberry")
EC_Straw_Cher_G7<-formattingplotpair(data_logchange, "7", "Strawberry", "Cherry")
EC_Cran_Cher_G29<-formattingplotpair(data_logchange, "29", "Cherry", "Cranberry")
EC_Straw_Cran_G29<-formattingplotpair(data_logchange, "29", "Cranberry", "Strawberry")
EC_Straw_Cher_G29<-formattingplotpair(data_logchange, "29", "Strawberry", "Cherry")
formattinglogchange <- function(logchange_dataset = data_logchange, generation="7",
fruitcomb=c("Cherry", "Cranberry"), trait="fecundity"){
## Extract sympatric combinations
TEMP_symp <- logchange_dataset[logchange_dataset$Generation==generation&
logchange_dataset$Treatment%in%fruitcomb&
logchange_dataset$Fruit_s%in%fruitcomb&logchange_dataset$SA==1,]
names(TEMP_symp)[6:ncol(TEMP_symp)] <- paste0(names(TEMP_symp)[6:ncol(TEMP_symp)], "_symp")
## Sort dataset
TEMP_symp <- TEMP_symp[order(TEMP_symp$Line),]
## Extract allopatric combinations
TEMP_allop <- logchange_dataset[logchange_dataset$Generation==generation&
logchange_dataset$Treatment%in%fruitcomb&
logchange_dataset$Fruit_s%in%fruitcomb&logchange_dataset$SA==0,]
names(TEMP_allop)[6:ncol(TEMP_allop)] <- paste0(names(TEMP_allop)[6:ncol(TEMP_allop)], "_allop")
## Sort dataset
TEMP_allop <- TEMP_allop[order(TEMP_allop$Line),]
## Combine datasets
if(identical(TEMP_symp$Line, TEMP_allop$Line)){
if(trait == "fitness"){
TEMP <- data.frame(TEMP_symp[, c(1:4, 6:9)], TEMP_allop[, 6:9])
TEMP$N_sumsympallop <- TEMP$N_symp + TEMP$N_allop
}else{
if (trait == "fecundity") {
TEMP <- data.frame(TEMP_symp[, c(1:4, 6, 10:12)], TEMP_allop[, c(6, 10:12)])
TEMP$N_sumsympallop <- TEMP$N_symp + TEMP$N_allop
}else{
if (trait == "eggtoad") {
TEMP <- data.frame(TEMP_symp[, c(1:4, 6, 13:15)], TEMP_allop[, c(6, 13:15)])
TEMP$N_sumsympallop <- TEMP$N_symp + TEMP$N_allop
}else{
print("Error: trait unknown")
}
}
}
}else{
print("Error: sympatric and allopatric datasets are not in the same order")
}
return(TEMP)
}
#Formatting for plot pool
TEMP_dataG29_CheCran <- formattinglogchange(data_logchange, "29", fruitcomb=c("Cherry", "Cranberry"), trait="fitness")
TEMP_dataG29_CranStraw <- formattinglogchange(data_logchange, "29", fruitcomb=c("Cranberry", "Strawberry"), trait="fitness")
TEMP_dataG29_StrawChe <- formattinglogchange(data_logchange, "29", fruitcomb=c("Strawberry", "Cherry"), trait="fitness")
## Data longitudinal
data_sum_allfruits <- loadlongitudinaldata_allfruits(dataset = "DATA_Adults_G1G29.csv", rm_generation_max = 5)
data_sum_allfruits_AN<-data_sum_allfruits[data_sum_allfruits$Generation!=1,]
#Limit axis
lim_G7<-max(abs(min(data_logchange[data_logchange$Generation=="7",]$lowCIlogfitnesschange, na.rm = T)),
max(data_logchange[data_logchange$Generation=="7",]$upCIlogfitnesschange, na.rm = T))
lim_G29<-max(abs(min(data_logchange[data_logchange$Generation=="29",]$upCIlogfitnesschange, na.rm = T)),
max(data_logchange[data_logchange$Generation=="29",]$upCIlogfitnesschange, na.rm = T))
#Plot
PAIR_StrawCran_G7<-ggplot(data = EC_Straw_Cran_G7,
aes(x = logchange_Strawberry,y = logchange_Cranberry, color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Cranberry,
ymax = upCIlogfitnesschange_Cranberry),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Strawberry,
xmax = upCIlogfitnesschange_Cranberry),
height=0.02,size=0.2,alpha=1) +
geom_point(shape=21, size=3, fill = "#ffffff", stroke=1.3) +
xlab("Fitness change\nin strawberry") +
ylab("Fitness change\nin cranberry") +
xlim(-lim_G7,lim_G7) +
ylim(-lim_G7,lim_G7) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
axis.title.y = element_text(size=10, colour = "#FDB424")) +
theme_LO_sober
PAIR_StrawCran_G7
PAIR_StrawChe_G7<-ggplot(data = EC_Straw_Cher_G7,
aes(x = logchange_Cherry,y = logchange_Strawberry, color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Strawberry,
ymax = upCIlogfitnesschange_Strawberry),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Cherry,
xmax = upCIlogfitnesschange_Cherry),
height=0.02, size=0.2, alpha=1) +
geom_point(shape=21, size=3, fill = "#ffffff", stroke=1.3) +
ylab("Fitness change\nin strawberry") +
xlab("Fitness change\nin cherry") +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
xlim(-lim_G7,lim_G7) +
ylim(-lim_G7,lim_G7) +
theme(axis.title.x = element_text(size=10, colour = "#BC3C6D"),
axis.title.y = element_text(size=10, colour = "#3FAA96")) +
theme_LO_sober
PAIR_StrawChe_G7
PAIR_CheCran_G7<-ggplot(data = EC_Cran_Cher_G7,aes(x = logchange_Cranberry,y = logchange_Cherry,
color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Cherry,
ymax = upCIlogfitnesschange_Cherry),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Cranberry,
xmax = upCIlogfitnesschange_Cranberry),
height=0.02, size=0.2, alpha=1) +
geom_point(shape=21, size=3, fill = "#ffffff", stroke=1.3) +
ylab("Fitness change\nin cherry") +
xlab("Fitness change\nin cranberry") +
xlim(-lim_G7, lim_G7) +
ylim(-lim_G7, lim_G7) +
scale_color_manual(values = c("#BC3C6D", "#FDB424", "#3FAA96")) +
theme_LO_sober +
theme(axis.title.x = element_text(colour = "#FDB424"),
axis.title.y = element_text(colour = "#BC3C6D"))
PAIR_CheCran_G7
################## Final phenotyping step
#Plot
PAIR_CranStraw_G29<-ggplot(data = EC_Straw_Cran_G29,
aes(x = logchange_Strawberry, y = logchange_Cranberry, color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Cranberry,
ymax = upCIlogfitnesschange_Cranberry),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Strawberry,
xmax = upCIlogfitnesschange_Strawberry),
height=0.02,size=0.2,alpha=1) +
geom_point(aes(fill = Fruit_s),shape=21, size=3) +
xlab("Fitness change\nin strawberry") +
ylab("Fitness change\nin cranberry") +
xlim(-lim_G29,lim_G29) +
ylim(-lim_G29,lim_G29) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
theme(axis.title.x = element_text(size=10, colour = "#3FAA96"),
axis.title.y = element_text(size=10, colour = "#FDB424")) +
theme_LO_sober
PAIR_CranStraw_G29
PAIR_StrawChe_G29<-ggplot(data = EC_Straw_Cher_G29,
aes(x = logchange_Cherry,y = logchange_Strawberry, color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Strawberry,
ymax = upCIlogfitnesschange_Strawberry),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Cherry,
xmax = upCIlogfitnesschange_Cherry),
height=0.02,size=0.2,alpha=1) +
geom_point(aes(fill = Fruit_s),shape=21, size=3) +
ylab("Fitness change\nin strawberry") +
xlab("Fitness change\nin cherry") +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
xlim(-lim_G29,lim_G29) +
ylim(-lim_G29,lim_G29) +
theme(axis.title.x = element_text(colour = "#BC3C6D"),
axis.title.y = element_text(colour = "#3FAA96")) +
theme_LO_sober
PAIR_StrawChe_G29
PAIR_CheCran_G29<-ggplot(data = EC_Cran_Cher_G29,
aes(x = logchange_Cranberry,y = logchange_Cherry, color=Fruit_s)) +
geom_errorbar(aes(ymin = lowCIlogfitnesschange_Cherry,
ymax = upCIlogfitnesschange_Cherry),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(xmin = lowCIlogfitnesschange_Cranberry,
xmax = upCIlogfitnesschange_Cranberry),
height=0.02,size=0.2,alpha=1) +
geom_point(aes(fill = Fruit_s), shape=21, size=3) +
ylab("Fitness change\nin cherry") +
xlab("Fitness change\nin cranberry") +
xlim(-lim_G29,lim_G29) +
ylim(-lim_G29,lim_G29) +
scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
theme_LO_sober +
theme(axis.title.x = element_text(colour = "#FDB424"),
axis.title.y = element_text(colour = "#BC3C6D"))
PAIR_CheCran_G29
#Legend
TEMP_data_logchange_sum_Straw_Cher_G7<-data_logchange
TEMP_data_logchange_sum_Straw_Cher_G7$Pheno<-sample(c("Intermediate", "Final"),
length(data_logchange$logchange),
replace=TRUE)
PAIR_plot_legend<- ggplot(data=TEMP_data_logchange_sum_Straw_Cher_G7,
aes(x=Treatment, y=logchange, group=Fruit_s, colour=Fruit_s,shape=Pheno)) +
geom_errorbar(aes(ymin=lowCIlogfitnesschange, ymax=upCIlogfitnesschange),
width=0.01,size=1) +
geom_point(size=3, stroke=1.3) +
scale_shape_manual(name = "Phenotyping step",
labels = c("Intermediate", "Final"),values=c(21,16)) +
scale_color_manual(name= "Selection fruit",
values=c("#BC3C6D", "#FDB424", "#3FAA96"),
label=c("Cherry", "Cranberry", "Strawberry")) +
theme_LO_sober
PAIR_legend<-lemon::g_legend(PAIR_plot_legend)
rm(TEMP_data_logchange_sum_Straw_Cher_G7)
PAIR_Fig_Sup <- cowplot::ggdraw() +
cowplot::draw_plot(PAIR_CheCran_G7+theme(legend.position = "none"),
x =0.00, y = 0.5, width = 0.22, height =0.45) +
cowplot::draw_plot(PAIR_StrawCran_G7+theme(legend.position = "none"),
x = 0.26, y = 0.5, width = 0.22, height = 0.45) +
cowplot::draw_plot(PAIR_StrawChe_G7+theme(legend.position = "none"),
x = 0.52, y = 0.5, width = 0.22, height = 0.45) +
cowplot::draw_plot(PAIR_legend, x = 0.80, y = 0.5, width = 0.1, height = 0.1) +
cowplot::draw_plot(PAIR_CheCran_G29+theme(legend.position = "none"),
x =0.00, y = 0, width = 0.22, height = 0.45) +
cowplot::draw_plot(PAIR_CranStraw_G29+theme(legend.position = "none"),
x = 0.26, y = 0, width = 0.22, height = 0.45) +
cowplot::draw_plot(PAIR_StrawChe_G29+theme(legend.position = "none"),
x = 0.52, y = 0, width = 0.22, height = 0.45) +
cowplot::draw_plot_label(c("Intermediate phenotyping step", "A", "B", "C", " ",
"Final phenotyping step", "D", "E", "F", " "),
x = c(0.26,0,0.26,0.52,0.82,0.2,0,0.26,0.52,0.82),
y = c(1.01,0.97,0.97,0.97,0.97,0.5,0.47, 0.47, 0.47, 0.47),
hjust = c(-0.25,-0.25,-0.25,-0.25,-0.25,-0.75,-0.75,-0.75,-0.75,-0.75),
vjust = c(1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5),
size = 14)
PAIR_Fig_Sup
cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pairwise.pdf"), PAIR_Fig_Sup,
base_height = 15/cm(1), base_width = 30/cm(1), dpi = 610)
tapply(data_G0$Nb_eggs, data_G0$Treatment, mean)
## Cherry Cranberry Strawberry
## 149.49 122.85 107.84
diag(tapply(data_G7$Nb_eggs, list(data_G7$Treatment,data_G7$Fruit_s), mean))
## Cherry Cranberry Strawberry
## 195.4375 181.1591 174.2923
diag(tapply(data_G29$Nb_eggs, list(data_G29$Treatment,data_G29$Fruit_s), mean))
## Cherry Cranberry Strawberry
## 103.7667 123.7000 126.7333
tapply(data_G0$Emergence_rate, data_G0$Treatment, mean)
## Cherry Cranberry Strawberry
## 0.1837216 0.2660867 0.2777895
diag(tapply(data_G7$Emergence_rate, list(data_G7$Treatment,data_G7$Fruit_s), mean))
## Cherry Cranberry Strawberry
## 0.1816565 0.2070999 0.2728989
diag(tapply(data_G29$Emergence_rate, list(data_G29$Treatment,data_G29$Fruit_s), mean))
## Cherry Cranberry Strawberry
## 0.3421827 0.2794123 0.3543303
## Compute correlation by generation and selective fruit
data_logchangeNb_eggsEmergence_rate<-data.frame(data_logchange[,c(1:6)],
Nb_eggslogchange=data_logchange[,"logfecundchange"],
Emergence_ratelogchange=data_logchange[,"logeggtoadchange"])
# plyr::ddply(data_logchangeNb_eggsEmergence_rate, .(Generation, Fruit_s), computecorrelation)
## WARNINGS: What is data_logchangeNb_eggsEmergence_rate?
#?????????
#Formating data
ymin = -50
ymax = 50
##################################################
################## G7
# Limits
vec_minmax <- function (data_set = data_logchange, gen = "7", fruit ="Cherry") {
ymin_PAIR_Che_G7=min(min(data_logchange[data_logchange$Generation==gen&
data_logchange$Fruit_s==fruit,]$lowCIlogfecundchange, na.rm= TRUE),
min(data_logchange[data_logchange$Generation==gen&
data_logchange$Fruit_s==fruit,]$lowCIlogeggtoadchange, na.rm= TRUE))
ymax_PAIR_Che_G7=max(max(data_logchange[data_logchange$Generation==gen&
data_logchange$Fruit_s==fruit,]$upCIlogfecundchange, na.rm= TRUE),
max(data_logchange[data_logchange$Generation==gen&
data_logchange$Fruit_s==fruit,]$upCIlogeggtoadchange, na.rm= TRUE))
vec_min_max<-c(ymin_PAIR_Che_G7,ymax_PAIR_Che_G7)
return(vec_min_max)
}
# Plot
PAIR_Che_G7 <- ggplot(data = data_logchange[data_logchange$Generation=="7"&
data_logchange$Fruit_s=="Cherry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change between\nintermediate and initial phenotyping steps") +
ylab("Logit egg-to-adult viability\nchange between intermediate\nand initial phenotyping steps") +
ggtitle("Evolved on Cherry") +
theme_LO_sober + theme(plot.title = element_text(color = "#BC3C6D")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(21, 22, 24)) +
scale_color_manual(values = c("#BC3C6D")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"7","Cherry"),
xlim = vec_minmax(data_logchange,"7","Cherry"))
PAIR_Che_G7
# Limits
PAIR_Cran_G7 <- ggplot(data = data_logchange[data_logchange$Generation=="7"&
data_logchange$Fruit_s=="Cranberry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change between\nintermediate and initial phenotyping steps") +
ylab("Logit egg-to-adult viability change between\nintermediate and initial phenotyping steps") +
ggtitle("Evolved on Cranberry") +
theme_LO_sober + theme(plot.title = element_text(color = "#FDB424")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(21, 22, 24)) +
scale_color_manual(values = c("#FDB424")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"7","Cranberry"),
xlim = vec_minmax(data_logchange,"7","Cranberry"))
PAIR_Cran_G7
# Limits
# Limits
PAIR_Straw_G7 <- ggplot(data = data_logchange[data_logchange$Generation=="7"&
data_logchange$Fruit_s=="Strawberry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change between\nintermediate and initial phenotyping steps") +
ylab("Logit egg-to-adult viability change between\nintermediate and initial phenotyping steps") +
ggtitle("Evolved on Strawberry") +
theme_LO_sober + theme(plot.title = element_text(color = "#3FAA96")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(21, 22, 24)) +
scale_color_manual(values = c("#3FAA96")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"7","Strawberry"),
xlim = vec_minmax(data_logchange,"7","Strawberry"))
PAIR_Straw_G7
#####################################################################################
################################## G29 ##################################
#####################################################################################
# Plot
PAIR_Che_G29 <- ggplot(data = data_logchange[data_logchange$Generation=="29"&
data_logchange$Fruit_s=="Cherry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change\nbetween final and\ninitial phenotyping steps") +
ylab("Logit egg-to-adult viability\nchange between final and\ninitial phenotyping steps") +
ggtitle("Evolved on Cherry") +
theme_LO_sober + theme(plot.title = element_text(color = "#BC3C6D")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(16, 15, 17)) +
scale_color_manual(values = c("#BC3C6D")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"29","Cherry"),
xlim = vec_minmax(data_logchange,"29","Cherry"))
PAIR_Che_G29
# Limits
PAIR_Cran_G29 <- ggplot(data = data_logchange[data_logchange$Generation=="29"&
data_logchange$Fruit_s=="Cranberry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change between\nfinal and initial phenotyping steps") +
ylab("Logit egg-to-adult viability change between\nfinal and initial phenotyping steps") +
ggtitle("Evolved on Cranberry") +
theme_LO_sober + theme(plot.title = element_text(color = "#FDB424")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(16, 15, 17)) +
scale_color_manual(values = c("#FDB424")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"29","Cranberry"),
xlim = vec_minmax(data_logchange,"29","Cranberry"))
PAIR_Cran_G29
# Limits
# Limits
PAIR_Straw_G29 <- ggplot(data = data_logchange[data_logchange$Generation=="29"&
data_logchange$Fruit_s=="Strawberry",]) +
geom_errorbar(aes(x = logfecundchange,
ymin = lowCIlogeggtoadchange,
ymax = upCIlogeggtoadchange,
color = Fruit_s),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logeggtoadchange,
xmin = lowCIlogfecundchange,
xmax = upCIlogfecundchange,
color = Fruit_s),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x = logfecundchange, y = logeggtoadchange,
color = Fruit_s, fill = Fruit_s, shape = Treatment),
size = 3, fill = "white", stroke =1.2) +
xlab("Log fecundity change between\nfinal and initial phenotyping steps") +
ylab("Logit egg-to-adult viability change between\nfinal and initial phenotyping steps") +
ggtitle("Evolved on Strawberry") +
theme_LO_sober + theme(plot.title = element_text(color = "#3FAA96")) +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(16, 15, 17)) +
scale_color_manual(values = c("#3FAA96")) +
coord_cartesian(ylim = vec_minmax(data_logchange,"29","Strawberry"),
xlim = vec_minmax(data_logchange,"29","Strawberry"))
PAIR_Straw_G29
legend_tradevide <- ggplot(data = data_logchange[data_logchange$Generation == "29",],
aes(x =logchange, y = logchange, fill = Fruit_s,
shape = Treatment)) +
geom_point(size =2.5, fill = "white") +
labs(shape = "Test fruit") +
scale_shape_manual(values = c(16, 15, 17)) +
theme_LO_sober
legend_trade <- lemon::g_legend(legend_tradevide)
CORRELATION_BETWEEN_TRAITS <- cowplot::ggdraw() +
cowplot::draw_plot(PAIR_Che_G7 + theme(legend.position = "none",
axis.title.y = element_text(size=12),
axis.title.x = element_blank()),
x = 0.01, y = 0.53, width = 0.3, height = 0.41) +
cowplot::draw_plot(PAIR_Cran_G7 + theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank()),
x = 0.34, y = 0.53, width = 0.26, height = 0.41) +
cowplot::draw_plot(PAIR_Straw_G7+ theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank()),
x = 0.61, y = 0.53, width = 0.26, height = 0.41) +
cowplot::draw_plot(legend_trade, x = 0.89, y = 0.5, width = 0.1, height = 0.1) +
cowplot::draw_plot(PAIR_Che_G29 + theme(legend.position = "none",
axis.title.y = element_text(size=12),
axis.title.x = element_blank()),
x = 0.01, y = 0.03, width = 0.3, height = 0.41) +
cowplot::draw_plot(PAIR_Cran_G29 + theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank()),
x = 0.34, y = 00.03, width = 0.26, height = 0.41) +
cowplot::draw_plot(PAIR_Straw_G29 + theme(legend.position = "none",
axis.title.x = element_blank(),
axis.title.y = element_blank()),
x = 0.61, y = 00.03, width = 0.26, height = 0.41) +
cowplot::draw_plot_label(c("Intermediate phenotyping step", "A", " ", " ", " ",
"Final phenotyping step", "B", " ", " ", " ",
"Log fecundity change between final and initial phenotyping steps",
"Log fecundity change between intermediate and initial phenotyping steps"),
x = c(0.28, 0.01, 0.34, 0.61, 0.92, 0.230, 0.01, 0.30, 0.61, 0.92,0.15,0.1),
y = c(0.99, 0.95, 0.95, 0.95, 0.95, 0.49, 0.45, 0.45, 0.45, 0.45, 0.05, 0.55),
hjust = c(-0.25, -0.25, -0.25, -0.25, -0.25, -0.75, -0.75, -0.75, -0.75, -0.75, -0.25, -0.25),
vjust = c(1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5),
size = c(rep(16,10),12.5,12.5),
fontface = c(rep("bold",10),"plain","plain"))
CORRELATION_BETWEEN_TRAITS
#
# #
#
cowplot::save_plot(file =here::here("figures", "SUPMAT_Correlation_between_Traits.pdf"),
CORRELATION_BETWEEN_TRAITS,
base_height = 16/cm(1), base_width = 26/cm(1), dpi = 610)
#To consider fruit maternal effect and GF maternal effect: new plot
## Y-axis = log change = log(Fitness pheno)-log(fitness initial)
## X-axis = fitness temp / fitness initial
## example: for CEA during first phase
## log(mean (CE1 from G2 to G5) / mean (Cherry G2))
##To check with Nico: for x-axis: denominator=mean Cherry G2 or mean CE1 G2 (???????????)
####### Phenotyping steps
#Remove allopatric data
data_fitness_pheno <- data_logchange[data_logchange$SA==1,]
data_fitness_pheno <- data_fitness_pheno[, c("Line", "Fruit_s", "logchange", "lowCIlogfitnesschange", "upCIlogfitnesschange")]
####### Longitudinal data
#Compute log change
data_logchange_long <- computelogchange_forlongdata(longitudinal_dataset = data_sum)
####### Merge data
data_compare_longitudinal_pheno <- merge(data_logchange_long,data_fitness_pheno,by=c("Line", "Fruit_s"))
data_compare_longitudinal_pheno <- droplevels(data_compare_longitudinal_pheno)
## Does not seem to be a correlation between measures
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="first_prepool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="first_prepool"])
cor.test(data_compare_longitudinal_pheno$logchange[data_compare_longitudinal_pheno$Phase=="second_postpool"], data_compare_longitudinal_pheno$logchange_long[data_compare_longitudinal_pheno$Phase=="second_postpool"])
####### Geary test
#Lines: CE2 and CR2 do not pass Geary's test (the threshold of a standardized mean greater than 3)
data_compare_longitudinal_pheno$Line_type <- ifelse(data_compare_longitudinal_pheno$Line == "CR2"|
data_compare_longitudinal_pheno$Line == "CE2", "solid","dashed")
PLOT_IntermediatePheno_LOGCHANGE<-ggplot(data=data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="first_prepool",],
aes(y=logchange,x=logchange_long, color=Fruit_s,shape=Fruit_s, linetype=Line_type)) +
geom_errorbar(aes(x = logchange_long,
ymin = logchange-(1.96*sd_logchange),
ymax = logchange+(1.96*sd_logchange)),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(y = logchange,
xmin = logchange_long-1.96*sd_logchange_long,
xmax = logchange_long+1.96*sd_logchange_long),
height=0.02,size=0.2,alpha=1) +
geom_point(size=3, fill = "#ffffff", stroke=1.3) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_shape_manual(values=c(21, 22, 24)) +
xlab("Fitness change between average fitness across generations 2 to 5\nand average fitness across generations 2 to 5") +
ylab("Fitness change between\nintermediate and initial phenotyping steps") +
labs(color="Selection fruit", shape="Selection fruit") +
geom_abline(intercept = 0, slope = 1, color="black", linetype="dashed", size=0.8) +
ylim(-1.9,0.9) +
xlim(-1.9,0.9) +
guides(linetype=FALSE) +
ggtitle("Intermediate phenotyping step vs. Phase 1") +
theme_LO_sober
PLOT_IntermediatePheno_LOGCHANGE
PLOT_FinalPheno_LOGCHANGE <-
ggplot(data=data_compare_longitudinal_pheno
[data_compare_longitudinal_pheno$Phase=="second_postpool",],
aes(y=logchange, x=logchange_long,
color=Fruit_s, shape=Fruit_s, fill=Fruit_s, linetype=Line_type)) +
geom_errorbar(aes(x = logchange_long,
ymin = logchange-(1.96*sd_logchange),
ymax = logchange+(1.96*sd_logchange)),
width=0.02,size=0.2,alpha=1) +
geom_errorbarh(aes(y = logchange,
xmin = logchange_long-1.96*sd_logchange_long,
xmax = logchange_long+1.96*sd_logchange_long),
height=0.02,size=0.2,alpha=1) +
geom_abline(intercept = 0, slope = 1, color="black",
linetype="dashed", size=0.8) +
geom_point(size=3, stroke=1) +
scale_fill_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_shape_manual(values=c(21, 22, 24)) +
xlab("Fitness change between average fitness across generations 13 to 26\nand average fitness across generations 2 to 5") +
ylab("Fitness change between\nfinal and initial phenotyping steps") +
labs(color="Selection fruit", shape="Selection fruit", fill="Selection fruit") +
ylim(-0.5,1.7) +
xlim(-0.5,1.7) +
guides(linetype=FALSE) +
ggtitle("Final phenotyping step vs. Phase 3") +
theme_LO_sober
PLOT_FinalPheno_LOGCHANGE
PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE <- cowplot::ggdraw() +
cowplot::draw_plot(PLOT_IntermediatePheno_LOGCHANGE +
theme(axis.title.y = element_text(size=10),
axis.title.x = element_text(size=10)),
x = 0, y = 0.5, width = 1, height = 0.5) +
cowplot::draw_plot(PLOT_FinalPheno_LOGCHANGE +
theme(axis.title.y = element_text(size=10),
axis.title.x = element_text(size=10)),
x =0, y = 0, width = 1, height = 0.5) +
cowplot::draw_plot_label(c("A", "B"),
x = c(0,0), y = c(1,0.5),
size = 14)
PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE
cowplot::save_plot(file=here::here("figures", "SUPMAT_LogChange_Pheno_Longitudinal.pdf"),
PLOT_Comparison_Pheno_Longitudinal_LOGCHANGE, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)
m <- lm(logchange ~ logchange_long + offset(logchange_long),
data = data_compare_longitudinal_pheno[data_compare_longitudinal_pheno$Phase=="second_postpool",])
summary(m)
#pval of logchange_long = 0.003 => slope is different of 1
#pval of Intercept = 0.80 => no evolution of maternal effect?
## Ratio maternal effects derived pop / maternal effect ancestral population
exp(coef(m)[1])
# proportion of adaptation due to maternal effects
data_compare_longitudinal_pheno$mateff <- (data_compare_longitudinal_pheno$logchange_long -
data_compare_longitudinal_pheno$logchange) / data_compare_longitudinal_pheno$logchange_long
data_compare_longitudinal_pheno
#Plot
PLOT_Maternaleffects<-ggplot(data=data_compare_longitudinal_pheno,
aes(y=mateff,x=logchange_long, color=Fruit_s, shape=Fruit_s, fill=interaction(Phase,Fruit_s))) +
geom_point(size=3, stroke=1.3) +
scale_fill_manual(name = "Phase",
values = c("#ffffff","#BC3C6D", "#ffffff","#FDB424", "#ffffff", "#3FAA96"),
breaks = c("first_prepool.Cherry", "second_postpool.Cherry"),
labels = c("Phase 1","Phase 3")) +
scale_color_manual(values=c("#BC3C6D", "#FDB424", "#3FAA96")) +
scale_shape_manual(values=c(21, 22, 24)) +
xlab("Fitness change between average fitness\nacross generations 2 to 5 (13 to 26) and generation 2") +
ylab("Proportion of adaptation\ndue to evolution of maternal effects") +
labs(color="Selection fruit", shape="Selection fruit") +
guides(fill = guide_legend(override.aes = list(fill = c("white","black"), shape=21))) +
theme_LO_sober
PLOT_Maternaleffects
cowplot::save_plot(file=here::here("figures", "SUPMAT_Maternal_effects.pdf"),
PLOT_Maternaleffects, base_height = 20/cm(1), base_width = 15/cm(1), dpi = 1200)
## Check random effect structure
mod1 <- lme4::lmer(fitness ~ Line*Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = TRUE)
mod2 <- lme4::lmer(fitness ~ Line*Generation + (1|Generation) + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = TRUE)
MuMIn::model.sel(mod1, mod2)
## Model selection table
## (Int) Gnr Lin Gnr:Lin family random df logLik AICc
## mod1 0.9538 -1.548 + + gaussian(identity) G:F_s 71 -46.078 526.3
## mod2 1.0300 -1.580 + + gaussian(identity) G+G:F_s 72 -46.060 545.3
## delta weight
## mod1 0.00 1
## mod2 19.02 0
## Models ranked by AICc(x)
## Random terms:
## G:F_s = '1 | Generation:Fruit_s'
## G = '1 | Generation'
##Cl: the model with the same generation effect across lines does not increase the likelihood and does not provide a better fit to the data
#Models
mod_all_interaction <- lme4::lmer(fitness ~ Fruit_s*Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_generation <- lme4::lmer(fitness ~ Generation + (1|Generation:Fruit_s) ,
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_fruit_generation <- lme4::lmer(fitness ~ Fruit_s+Generation + (1|Generation:Fruit_s) ,
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_fruit <- lme4::lmer(fitness ~ Fruit_s + (1|Generation:Fruit_s) ,
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_line <- lme4::lmer(fitness ~ Line + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_null <- lme4::lmer(fitness ~ 1 + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_all_interaction_line_generation <- lme4::lmer(fitness ~ Line*Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
mod_line_generation <- lme4::lmer(fitness ~ Line+Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN, REML = FALSE)
MuMIn::model.sel(mod_all_interaction,mod_all_fruit_generation,mod_all_fruit,mod_all_null,mod_all_generation,mod_all_line,mod_all_interaction_line_generation,mod_line_generation)
## Model selection table
## (Int) Frt_s Gnr Frt_s:Gnr Lin
## mod_all_interaction -1.2580 + -0.56070 +
## mod_all_fruit -2.4250 +
## mod_all_fruit_generation -2.3690 + -0.02678
## mod_all_line -2.3980 +
## mod_line_generation -2.1860 -0.08907 +
## mod_all_generation -1.8340 0.27440
## mod_all_null -0.9906
## mod_all_interaction_line_generation 0.9538 -1.54800 +
## Gnr:Lin family df logLik
## mod_all_interaction gaussian(identity) 18 -80.610
## mod_all_fruit gaussian(identity) 10 -92.408
## mod_all_fruit_generation gaussian(identity) 11 -92.306
## mod_all_line gaussian(identity) 42 -37.016
## mod_line_generation gaussian(identity) 43 -35.790
## mod_all_generation gaussian(identity) 4 -112.481
## mod_all_null gaussian(identity) 3 -114.229
## mod_all_interaction_line_generation + gaussian(identity) 71 6.826
## AICc delta weight
## mod_all_interaction 205.0 0.00 0.681
## mod_all_fruit 207.1 2.12 0.236
## mod_all_fruit_generation 209.4 4.40 0.076
## mod_all_line 214.5 9.48 0.006
## mod_line_generation 217.6 12.65 0.001
## mod_all_generation 233.4 28.36 0.000
## mod_all_null 234.7 29.70 0.000
## mod_all_interaction_line_generation 420.5 215.47 0.000
## Models ranked by AICc(x)
## Random terms (all models):
## '1 | Generation:Fruit_s'
summary(mod_all_interaction)
## Linear mixed model fit by maximum likelihood ['lmerMod']
## Formula: fitness ~ Fruit_s * Generation + (1 | Generation:Fruit_s)
## Data: data_sum_allfruits_AN
## Weights: N
##
## AIC BIC logLik deviance df.resid
## 197.2 245.3 -80.6 161.2 89
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.8179 -0.7264 0.0873 0.6984 2.2653
##
## Random effects:
## Groups Name Variance Std.Dev.
## Generation:Fruit_s (Intercept) 0.000 0.000
## Residual 1.813 1.346
## Number of obs: 107, groups: Generation:Fruit_s, 25
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) -1.2579 1.4340 -0.877
## Fruit_sCherry 0.1344 1.4604 0.092
## Fruit_sCranberry 1.7136 1.4583 1.175
## Fruit_sFig 1.1471 1.4909 0.769
## Fruit_sGrape -3.4559 3.1334 -1.103
## Fruit_sRosehips -2.6107 1.6847 -1.550
## Fruit_sStrawberry 0.5629 1.4584 0.386
## Fruit_sTomato -1.5720 1.7459 -0.900
## Generation -0.5607 0.6930 -0.809
## Fruit_sCherry:Generation 0.7404 0.6988 1.060
## Fruit_sCranberry:Generation 0.2725 0.6979 0.391
## Fruit_sFig:Generation 0.2539 0.7097 0.358
## Fruit_sGrape:Generation 1.6698 1.5329 1.089
## Fruit_sRosehips:Generation 1.3420 0.8036 1.670
## Fruit_sStrawberry:Generation 0.6427 0.6980 0.921
## Fruit_sTomato:Generation 1.1111 0.8101 1.371
## convergence code: 0
## boundary (singular) fit: see ?isSingular
#Posthoc
mod_all_interaction <- lme4::lmer(fitness ~ Fruit_s*Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum_allfruits_AN)
summary(mod_all_interaction)
## Linear mixed model fit by REML ['lmerMod']
## Formula: fitness ~ Fruit_s * Generation + (1 | Generation:Fruit_s)
## Data: data_sum_allfruits_AN
## Weights: N
##
## REML criterion at convergence: 184.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.59867 -0.66991 0.08051 0.64407 2.08904
##
## Random effects:
## Groups Name Variance Std.Dev.
## Generation:Fruit_s (Intercept) 0.000 0.00
## Residual 2.132 1.46
## Number of obs: 107, groups: Generation:Fruit_s, 25
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) -1.2579 1.5550 -0.809
## Fruit_sCherry 0.1344 1.5836 0.085
## Fruit_sCranberry 1.7136 1.5813 1.084
## Fruit_sFig 1.1471 1.6166 0.710
## Fruit_sGrape -3.4559 3.3977 -1.017
## Fruit_sRosehips -2.6107 1.8268 -1.429
## Fruit_sStrawberry 0.5629 1.5815 0.356
## Fruit_sTomato -1.5720 1.8931 -0.830
## Generation -0.5607 0.7515 -0.746
## Fruit_sCherry:Generation 0.7404 0.7577 0.977
## Fruit_sCranberry:Generation 0.2725 0.7568 0.360
## Fruit_sFig:Generation 0.2539 0.7695 0.330
## Fruit_sGrape:Generation 1.6698 1.6622 1.005
## Fruit_sRosehips:Generation 1.3420 0.8714 1.540
## Fruit_sStrawberry:Generation 0.6427 0.7569 0.849
## Fruit_sTomato:Generation 1.1111 0.8785 1.265
## convergence code: 0
## boundary (singular) fit: see ?isSingular
emt1 <- emmeans::emtrends(mod_all_interaction, "Fruit_s", var = "Generation")
emt1 ### estimated slopes of Generation for each level of Fruit_s
## Fruit_s Generation.trend SE df lower.CL upper.CL
## Blackcurrant -0.561 0.7580 83.7 -2.0682 0.9468
## Cherry 0.180 0.0978 1460.0 -0.0122 0.3715
## Cranberry -0.288 0.0904 1415.8 -0.4654 -0.1109
## Fig -0.307 0.1684 606.9 -0.6375 0.0238
## Grape 1.109 1.4834 105.0 -1.8321 4.0504
## Rosehips 0.781 0.4431 116.4 -0.0963 1.6589
## Strawberry 0.082 0.0915 1262.4 -0.0974 0.2614
## Tomato 0.550 0.4584 107.6 -0.3583 1.4591
##
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
pairs(emt1) ### comparison of slopes
## contrast estimate SE df t.ratio p.value
## Blackcurrant - Cherry -0.7404 0.764 85.8 -0.969 0.9776
## Blackcurrant - Cranberry -0.2725 0.763 85.5 -0.357 1.0000
## Blackcurrant - Fig -0.2539 0.777 88.9 -0.327 1.0000
## Blackcurrant - Grape -1.6698 1.666 111.0 -1.002 0.9732
## Blackcurrant - Rosehips -1.3420 0.878 92.0 -1.528 0.7902
## Blackcurrant - Strawberry -0.6427 0.764 85.5 -0.842 0.9901
## Blackcurrant - Tomato -1.1111 0.886 89.8 -1.254 0.9129
## Cherry - Cranberry 0.4678 0.133 1440.9 3.513 0.0108
## Cherry - Fig 0.4865 0.195 734.1 2.498 0.1977
## Cherry - Grape -0.9295 1.487 105.8 -0.625 0.9985
## Cherry - Rosehips -0.6016 0.454 124.9 -1.326 0.8874
## Cherry - Strawberry 0.0977 0.134 1364.1 0.729 0.9961
## Cherry - Tomato -0.3707 0.469 114.9 -0.791 0.9933
## Cranberry - Fig 0.0187 0.191 713.6 0.098 1.0000
## Cranberry - Grape -1.3973 1.486 105.7 -0.940 0.9813
## Cranberry - Rosehips -1.0694 0.452 123.7 -2.365 0.2681
## Cranberry - Strawberry -0.3701 0.129 1334.9 -2.879 0.0777
## Cranberry - Tomato -0.8385 0.467 113.8 -1.795 0.6250
## Fig - Grape -1.4160 1.493 107.1 -0.948 0.9804
## Fig - Rosehips -1.0881 0.474 136.9 -2.295 0.3037
## Fig - Strawberry -0.3888 0.192 702.2 -2.029 0.4627
## Fig - Tomato -0.8572 0.488 125.1 -1.755 0.6511
## Grape - Rosehips 0.3278 1.548 107.6 0.212 1.0000
## Grape - Strawberry 1.0271 1.486 105.7 0.691 0.9971
## Grape - Tomato 0.5588 1.553 108.1 0.360 1.0000
## Rosehips - Strawberry 0.6993 0.452 123.7 1.546 0.7811
## Rosehips - Tomato 0.2309 0.638 112.1 0.362 1.0000
## Strawberry - Tomato -0.4684 0.467 113.9 -1.002 0.9733
##
## Degrees-of-freedom method: kenward-roger
## P value adjustment: tukey method for comparing a family of 8 estimates
pd <- position_dodge(0.3) # move them .05 to the left and right
#Extract slope and intercept
dat_8fruits <- expand.grid(Generation=as.numeric(levels(as.factor(data_sum_allfruits_AN$Generation))),
Fruit_s=unique(data_sum_allfruits_AN$Fruit_s))
dat_8fruits$fitness_predicted <- predict(mod_all_interaction, newdata = dat_8fruits,
re.form= NA, type = "response")
PLOT_CHERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cherry",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cherry",],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) +
ylim(-5.65, 1.25) +
ylab("Fitness") +
xlab("Generation") +
xlim("1","2","3","4","5") +
scale_color_manual(values = c("black", "#BC3C6D")) +
ggtitle("Cherry") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#BC3C6D"))
PLOT_CHERRY
PLOT_CRANBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Cranberry",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Cranberry",],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) +
ylim(-5.65, 1.25) +
ylab("Fitness") +
xlim("1","2","3","4","5") +
xlab("Generation") +
scale_color_manual(values = c("black","#FDB424")) +
ggtitle("Cranberry") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#FDB424"))
PLOT_CRANBERRY
PLOT_STRAWBERRY <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Strawberry",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Strawberry",],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c("black","#3FAA96")) +
ggtitle("Strawberry") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#3FAA96"))
PLOT_STRAWBERRY
PLOT_GRAPE <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Grape",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Grape"&dat_8fruits$Generation == c(2,3),],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c("black","#7B7554")) +
ggtitle("Grape") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#7B7554"))
PLOT_GRAPE
PLOT_ROSEHIPS <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Rosehips",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Rosehips"&dat_8fruits$Generation != 5,],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white",stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c("black","#8ACDEA")) +
ggtitle("Rose hips") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#8ACDEA"))
PLOT_ROSEHIPS
PLOT_TOMATO <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Tomato",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Tomato"&dat_8fruits$Generation != 5,],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c( "black","#ED6F47")) +
ggtitle("Tomato") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#ED6F47"))
PLOT_TOMATO
PLOT_FIG <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Fig",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Fig"&dat_8fruits$Generation != 5,],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c("black","#93194F")) +
ggtitle("Fig") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#93194F"))
PLOT_FIG
PLOT_BLACKCURRANT <- ggplot(data = data_sum_allfruits[data_sum_allfruits$Fruit_s == "Blackcurrant",],
aes(x = factor(Generation), group = Line, y = fitness, colour =Fruit_s)) +
geom_errorbar(aes(ymin = fitness-1.96*se_fitness, ymax = fitness + 1.96*se_fitness),
width=.1,position = pd, size = 0.4,color = "black") +
geom_line(size = 0.5,position = pd) +
geom_line(data = dat_8fruits[dat_8fruits$Fruit_s == "Blackcurrant"&dat_8fruits$Generation == c(2,3),],
aes(x = factor(Generation), y = fitness_predicted, colour = "black", group=NA), size = 0.7) +
geom_point(size = 2, position = pd, shape = 21, fill = "white", stroke = 1.2) +
ylim(-5.65, 1.25) +
xlim("1","2","3","4","5") +
ylab("Fitness") +
xlab("Generation") +
scale_color_manual(values = c( "black","#203753")) +
ggtitle("Blackcurrant") +
theme_LO_adaptation + theme(plot.title = element_text(color = "#203753"))
PLOT_BLACKCURRANT
DYNAMIC_EIGHT_JOIN <- cowplot::ggdraw() +
cowplot::draw_plot(PLOT_STRAWBERRY, x = 0, y = 0, width = 0.5, height = 0.28) +
cowplot::draw_plot(PLOT_GRAPE+ theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0, y = 0.28, width = 0.5, height = 0.23) +
cowplot::draw_plot(PLOT_CRANBERRY+ theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0, y = 0.53, width = 0.5, height = 0.23) +
cowplot::draw_plot(PLOT_BLACKCURRANT+ theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0, y = 0.77, width = 0.5, height = 0.23) +
cowplot::draw_plot(PLOT_TOMATO+ theme(axis.title.y = element_blank()),
x = 0.5, y = 0, width = 0.5, height = 0.28) +
cowplot::draw_plot(PLOT_ROSEHIPS+ theme(axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0.5, y = 0.28, width = 0.5, height = 0.23) +
cowplot::draw_plot(PLOT_FIG+ theme(axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0.5, y = 0.53, width = 0.5, height = 0.23) +
cowplot::draw_plot(PLOT_CHERRY + theme(axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank()),
x = 0.5, y = 0.77, width = 0.5, height = 0.23) +
cowplot::draw_plot_label(c("A", "C", "E", "G", "B", "D", "F", "H"),
x = c(0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5),
y = c(1, 0.75, 0.50, 0.27, 1, 0.75, 0.5, 0.27),
hjust = c(-0.5, -0.5, -0.5,-0.5, -0.5, -0.5, -0.5, -0.5),
vjust = c(1.5, 1.5, 1.5,1.5, 1.5, 1.5,1.5, 1.5),
size = 12)
DYNAMIC_EIGHT_JOIN
cowplot::save_plot(file =here::here("figures", "SUPMAT_Fitness8Fruits.pdf"), DYNAMIC_EIGHT_JOIN, base_height = 17/cm(1), base_width = 15/cm(1), dpi = 1200)
################### PHASE 3
## Test for random effects
mod0 <- lme4::lmer(fitness~ Generation*Line + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = TRUE)
mod1 <- lme4::lmer(fitness~ Generation*Line + (1|Generation) + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = TRUE)
MuMIn::model.sel(mod0, mod1)
## Model selection table
## (Int) Gnr Lin Gnr:Lin family random df logLik AICc
## mod0 0.9619 -0.01430 + + gaussian(identity) G:F_s 24 -116.602 289.2
## mod1 0.9546 -0.01397 + + gaussian(identity) G+G:F_s 25 -115.849 290.4
## delta weight
## mod0 0.00 0.647
## mod1 1.21 0.353
## Models ranked by AICc(x)
## Random terms:
## G:F_s = '1 | Generation:Fruit_s'
## G = '1 | Generation'
## Cl: only a very slight increase in likelihood when adding the second random effect
## Test for fixed effects
mod1 <- lme4::lmer(fitness ~ 1 + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod2 <- lme4::lmer(fitness~ Line + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod3 <- lme4::lmer(fitness ~ Fruit_s + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod4 <- lme4::lmer(fitness~ Generation*Line + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod5 <- lme4::lmer(fitness~ Generation+Line + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod6 <- lme4::lmer(fitness ~ Generation*Fruit_s + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod7 <- lme4::lmer(fitness ~ Generation+Fruit_s + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
mod8 <- lme4::lmer(fitness ~ Generation + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",], REML = FALSE)
anova(mod1,mod2)
## Data: data_sum[data_sum$Phase == "second_postpool", ]
## Models:
## mod1: fitness ~ 1 + (1 | Generation:Fruit_s)
## mod2: fitness ~ Line + (1 | Generation:Fruit_s)
## npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
## mod1 3 183.90 193.41 -88.949 177.90
## mod2 13 180.93 222.15 -77.466 154.93 22.966 10 0.01087 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
MuMIn::model.sel(mod1,mod2,mod3,mod4,mod5,mod6, mod7, mod8)
## Model selection table
## (Int) Lin Frt_s Gnr Gnr:Lin Frt_s:Gnr family df logLik
## mod3 0.6953 + gaussian(identity) 5 -85.570
## mod7 0.8959 + -0.010180 gaussian(identity) 6 -85.075
## mod2 0.6794 + gaussian(identity) 13 -77.466
## mod1 0.5241 gaussian(identity) 3 -88.949
## mod5 0.8956 + -0.010990 gaussian(identity) 14 -76.903
## mod8 0.7116 -0.009572 gaussian(identity) 4 -88.569
## mod6 0.7081 + -0.000622 + gaussian(identity) 8 -84.555
## mod4 0.9618 + -0.014300 + gaussian(identity) 24 -67.423
## AICc delta weight
## mod3 181.5 0.00 0.362
## mod7 182.6 1.15 0.203
## mod2 183.2 1.69 0.156
## mod1 184.0 2.54 0.101
## mod5 184.4 2.92 0.084
## mod8 185.4 3.88 0.052
## mod6 186.0 4.48 0.039
## mod4 190.8 9.30 0.003
## Models ranked by AICc(x)
## Random terms (all models):
## '1 | Generation:Fruit_s'
mod3 <- lme4::lmer(fitness ~ Fruit_s-1 + (1|Generation) + (1|Generation:Fruit_s),
weights = N, data = data_sum[data_sum$Phase=="second_postpool",])
summary(mod3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: fitness ~ Fruit_s - 1 + (1 | Generation) + (1 | Generation:Fruit_s)
## Data: data_sum[data_sum$Phase == "second_postpool", ]
## Weights: N
##
## REML criterion at convergence: 179
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -4.9294 -0.2956 0.0853 0.4437 2.0606
##
## Random effects:
## Groups Name Variance Std.Dev.
## Generation:Fruit_s (Intercept) 0.05947 0.2439
## Generation (Intercept) 0.02245 0.1498
## Residual 2.44241 1.5628
## Number of obs: 176, groups: Generation:Fruit_s, 48; Generation, 16
##
## Fixed effects:
## Estimate Std. Error t value
## Fruit_sCherry 0.69438 0.08542 8.129
## Fruit_sCranberry 0.49602 0.08074 6.143
## Fruit_sStrawberry 0.38278 0.08553 4.475
##
## Correlation of Fixed Effects:
## Frt_sCh Frt_sCr
## Frt_sCrnbrr 0.204
## Frt_sStrwbr 0.192 0.204
########### Hypothesis 1
#Hypothesis 1: effect of pool
#Take the mean of all populations for each selection fruit
CheCran_hypo1 <- computelogchange_POOL_hypo1(data_G7, "Cherry", "Cranberry")
########### Hypothesis 2
#Hypothesis 2: effect of pool
#Take the fitness change of the population with the highest fitness in G7
TEMP_dataG7_CheCran <- formattinglogchange(data_logchange, "7", "Cherry", "Cranberry")
fittest_lines<-computelogchange_POOL_hypo2(data_G7, "Cherry", "Cranberry")
CheCran_hypo2<-TEMP_dataG7_CheCran[TEMP_dataG7_CheCran$Line==fittest_lines,]
#Initial plot from main text
ymin = -50
ymax = 50
pd <- position_dodge(0.3) # move them .05 to the left and right
# Limits
ymin_CheCranG29=min(min(TEMP_dataG29_CheCran$logchange_allop-1.96*TEMP_dataG29_CheCran$sd_allop, na.rm= TRUE),
min(TEMP_dataG29_CheCran$logchange_symp-1.96*TEMP_dataG29_CheCran$sd_symp, na.rm= TRUE))
ymax_CheCranG29=max(max(TEMP_dataG29_CheCran$logchange_allop + 1.96*TEMP_dataG29_CheCran$sd_allop, na.rm= TRUE),
max(TEMP_dataG29_CheCran$logchange_symp + 1.96*TEMP_dataG29_CheCran$sd_symp, na.rm= TRUE))
CheCran_G29 <- ggplot(data = TEMP_dataG29_CheCran) +
geom_errorbar(aes(x =logchange_symp, ymin = logchange_allop-(1.96*sd_allop),
ymax = logchange_allop + (1.96*sd_allop),
color = Symp),
width= 0.02, size = 0.3, alpha = 0.8) +
geom_errorbarh(aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp,
color = Symp),
height = 0.02, size = 0.3, alpha = 0.8) +
geom_point(aes(x =logchange_symp, y = logchange_allop, color = Symp,fill = Symp, shape = Allop),
size =3, fill = "white", stroke =1.2) +
xlab("Fitness change in\nselective environment") +
ylab("Fitness change in\nalternative environment") +
ggtitle("Cherry vs. Cranberry") +
labs(shape = "Test fruit", color = "Evolution fruit") +
scale_shape_manual(values = c(16, 15)) +
scale_color_manual(values = c("#BC3C6D", "#FDB424")) +
coord_cartesian(ylim = c(ymin_CheCranG29, ymax_CheCranG29),
xlim = c(ymin_CheCranG29, ymax_CheCranG29)) +
theme_LO_sober
CheCran_G29
PLOT_HYPO_1<-CheCran_G29 +
geom_errorbar(data = CheCran_hypo1, aes(x =logchange_symp, ymin = logchange_allop-(1.96*sd_allop),
ymax = logchange_allop + (1.96*sd_allop),
color = Symp),
width= 0.02, size = 0.2, alpha =1) +
geom_errorbarh(data = CheCran_hypo1,
aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp,
color = Symp),
height = 0.02, size = 0.2, alpha =1) +
geom_point(data = CheCran_hypo1,
aes(x =logchange_symp, y = logchange_allop, color = Symp,fill = Symp, shape = Allop),
size = 6, fill = "white", stroke = 2) +
geom_point(data = CheCran_hypo1,
aes(x =logchange_symp, y = logchange_allop, fill = Symp, shape = Allop),
size = 3, fill = "white", color = "white", stroke = 2) +
ggtitle("Hypothesis 1: Mean of populations effect")
PLOT_HYPO_1
PLOT_HYPO_2<-CheCran_G29 +
geom_errorbar(data = CheCran_hypo2, aes(x = logchange_symp,
ymin = logchange_allop-(1.96*sd_allop),
ymax = logchange_allop + (1.96*sd_allop),
color = Symp),
width= 0.02, size = 0.2, alpha =1) +
geom_errorbarh(data = CheCran_hypo2,
aes(y = logchange_allop, xmin = logchange_symp-1.96*sd_symp, xmax = logchange_symp + 1.96*sd_symp,
color = Symp),
height = 0.02, size = 0.2, alpha =1) +
geom_point(data = CheCran_hypo2,
aes(x =logchange_symp, y = logchange_allop, color = Symp,fill = Symp, shape = Allop),
size = 6, fill = "white", stroke = 2) +
geom_point(data = CheCran_hypo2,
aes(x = logchange_symp, y = logchange_allop, fill = Symp, shape = Allop),
size = 3, fill = "white", color = "white", stroke = 2) +
ggtitle("Hypothesis 2: Fittest population effect")
PLOT_HYPO_2
#legend1
legend_tradevide<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
width=0.4,size=0.4, alpha=0.3) +
labs(colour = "Population \nevolved on:") +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
legend_tradevide<-lemon::g_legend(legend_tradevide)
#legend hypo 1
legend_hypo1<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
width=0.4,size=0.4, alpha=0.3) +
labs(colour = "Mean of population\nevolved on:") +
geom_point(size=2, shape=21, fill="white", stroke = 2) +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
extract_legend_hypo1<-lemon::g_legend(legend_hypo1)
#legend2
legend_hypo2<- ggplot(CheCran_hypo2, aes(x=logchange_symp, y=logchange_allop, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
geom_errorbar(aes(ymin=logchange_allop-(1.96*sd_allop), ymax=logchange_allop+(1.96*sd_allop),),
width=0.4,size=0.4, alpha=0.3) +
labs(colour = "Population with \nthe highest fitness \non each selection fruit:") +
geom_point(size=2, shape=21, fill="white", stroke = 2) +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
extract_legend_hypo2<-lemon::g_legend(legend_hypo2)
ERRORCROSSES_G7_HYPO1_2 <- cowplot::ggdraw() +
cowplot::draw_plot(PLOT_HYPO_1+theme(legend.position = "none"),
x =0.00, y = 0.5, width = 0.75, height = 0.5) +
cowplot::draw_plot(PLOT_HYPO_2+theme(legend.position = "none"),
x = 0.0, y = 0, width = 0.75, height = 0.5) +
cowplot::draw_plot(legend_tradevide, x = 0.78, y = 0.85, width = 0.1, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo1, x = 0.82, y = 0.7, width = 0.1, height = 0.1) +
cowplot::draw_plot(legend_tradevide, x = 0.76, y = 0.35, width = 0.1, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo2, x = 0.82, y = 0.2, width = 0.1, height = 0.1)
ERRORCROSSES_G7_HYPO1_2
ERRORCROSSES_G7_HYPO1 <- cowplot::ggdraw() +
cowplot::draw_plot(PLOT_HYPO_1+theme(legend.position = "none",
plot.title = element_blank()),
x =0.00, y = 0, width = 0.75, height = 1) +
cowplot::draw_plot(legend_tradevide, x = 0.78, y = 0.3, width = 0.1, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo1, x = 0.82, y = 0.55, width = 0.1, height = 0.1)
ERRORCROSSES_G7_HYPO1
ERRORCROSSES_G7_HYPO2 <- cowplot::ggdraw() +
cowplot::draw_plot(PLOT_HYPO_2+theme(legend.position = "none",
plot.title = element_blank()),
x =0.00, y = 0, width = 0.75, height = 1) +
cowplot::draw_plot(legend_tradevide, x = 0.76, y = 0.3, width = 0.1, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo2, x = 0.82, y = 0.55, width = 0.1, height = 0.1)
ERRORCROSSES_G7_HYPO2
#
# cowplot::save_plot(file =here::here("figures", "SUPMAT_Pooleffect_Hypothesis.pdf"),
# ERRORCROSSES_G7_HYPO1_2,
# base_height = 18/cm(1), base_width = 15/cm(1), dpi = 610)
#
#
cowplot::save_plot(file =here::here("figures", "SUPMAT_Pooleffect_Hypothesis1.pdf"),
ERRORCROSSES_G7_HYPO1,
base_height = 12/cm(1), base_width = 15/cm(1), dpi = 610)
cowplot::save_plot(file =here::here("figures", "SUPMAT_Pooleffect_Hypothesis2.pdf"),
ERRORCROSSES_G7_HYPO2,
base_height = 12/cm(1), base_width = 15/cm(1), dpi = 610)
PAIR_StrawChe_G29
PAIR_CranStraw_G29
PAIR_CheCran_G29
## Data
# EC_Cran_Cher_G7<-formattingplotpair(data_logchange, "7", "Cherry", "Cranberry")
# EC_Straw_Cran_G7<-formattingplotpair(data_logchange, "7", "Cranberry", "Strawberry")
# EC_Straw_Cher_G7<-formattingplotpair(data_logchange, "7", "Strawberry", "Cherry")
########### Hypothesis 1
#Hypothesis 1: effect of pool
#Take the mean of all populations for each selection fruit
dataset_hypo1 <- formatting_POOL_hypo1(fitness_dataset_intermediate = data_G7)
########### Hypothesis 2
#Hypothesis 2: effect of pool
#Take the fitness change of the population with the highest fitness in G7
fittest_lines<-formatting_POOL_hypo2(data_G7)
EC_Cran_Cher_hypo2<-EC_Cran_Cher_G7[EC_Cran_Cher_G7$Line == fittest_lines[1]|
EC_Cran_Cher_G7$Line == fittest_lines[2]|
EC_Cran_Cher_G7$Line == fittest_lines[3],]
EC_Straw_Cran_hypo2<-EC_Straw_Cran_G7[EC_Straw_Cran_G7$Line == fittest_lines[1]|
EC_Straw_Cran_G7$Line == fittest_lines[2]|
EC_Straw_Cran_G7$Line == fittest_lines[3],]
EC_Straw_Cher_hypo2<-EC_Straw_Cher_G7[EC_Straw_Cher_G7$Line == fittest_lines[1]|
EC_Straw_Cher_G7$Line == fittest_lines[2]|
EC_Straw_Cher_G7$Line == fittest_lines[3],]
PAIR_CheCran_G29_HYPO_1 <- PAIR_CheCran_G29 +
geom_errorbar(data = dataset_hypo1,
aes(x=logchange_Strawberry,
ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = dataset_hypo1,
aes(y=logchange_Cranberry,
xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = dataset_hypo1,
aes(x = logchange_Strawberry, y = logchange_Cranberry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_CheCran_G29_HYPO_1
PAIR_StrawChe_G29_HYPO_1<-PAIR_StrawChe_G29 +
geom_errorbar(data = dataset_hypo1,
aes(x=logchange_Strawberry,
ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = dataset_hypo1,
aes(y=logchange_Cranberry,
xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = dataset_hypo1,
aes(x = logchange_Strawberry, y = logchange_Cranberry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_StrawChe_G29_HYPO_1
PAIR_CranStraw_G29_HYPO_1<-PAIR_StrawChe_G29 +
geom_errorbar(data = dataset_hypo1,
aes(x=logchange_Strawberry,
ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry, Line=NA),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = dataset_hypo1,
aes(y=logchange_Cranberry,
xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = dataset_hypo1,
aes(x = logchange_Strawberry, y = logchange_Cranberry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_CranStraw_G29_HYPO_1
PAIR_CranStraw_G29_HYPO_2 <- PAIR_CranStraw_G29 +
geom_errorbar(data = EC_Straw_Cran_hypo2,
aes(x=logchange_Strawberry,
ymin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
ymax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = EC_Straw_Cran_hypo2,
aes(y=logchange_Cranberry,
xmin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
xmax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = EC_Straw_Cran_hypo2,
aes(x = logchange_Strawberry, y = logchange_Cranberry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_CranStraw_G29_HYPO_2
PAIR_StrawChe_G29_HYPO_2 <- PAIR_StrawChe_G29 +
geom_errorbar(data = EC_Straw_Cher_hypo2,
aes(x=logchange_Cherry,
ymin = logchange_Strawberry-1.96*sd_logchange_Strawberry,
ymax = logchange_Strawberry+1.96*sd_logchange_Strawberry),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = EC_Straw_Cher_hypo2,
aes(y=logchange_Strawberry,
xmin = logchange_Cherry-1.96*sd_logchange_Cherry,
xmax = logchange_Cherry+1.96*sd_logchange_Cherry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = EC_Straw_Cher_hypo2,
aes(x = logchange_Cherry, y = logchange_Strawberry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_StrawChe_G29_HYPO_2
PAIR_CheCran_G29_HYPO_2<-PAIR_CheCran_G29 +
geom_errorbar(data = EC_Cran_Cher_hypo2,
aes(x=logchange_Cranberry,
ymin = logchange_Cherry-1.96*sd_logchange_Cherry,
ymax = logchange_Cherry+1.96*sd_logchange_Cherry),
width=0.02, size=0.2, alpha=1) +
geom_errorbarh(data = EC_Cran_Cher_hypo2,
aes(y=logchange_Cherry,
xmin = logchange_Cranberry-1.96*sd_logchange_Cranberry,
xmax = logchange_Cranberry+1.96*sd_logchange_Cranberry),
height=0.02, size=0.2, alpha=1) +
geom_point(data = EC_Cran_Cher_hypo2,
aes(x = logchange_Cranberry, y = logchange_Cherry),
shape=21, size=4, fill = "#ffffff", stroke=1.5)
PAIR_CheCran_G29_HYPO_2
#legend1
legend_tradevide<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry,
y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
labs(colour = "Population \nevolved on:") +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
legend_tradevide<-lemon::g_legend(legend_tradevide)
#legend hypo 1
legend_hypo1<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry,
y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
labs(colour = "Mean of population\nevolved on:") +
geom_point(size=2, shape=21, fill="white", stroke = 2) +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
extract_legend_hypo1<-lemon::g_legend(legend_hypo1)
#legend2
legend_hypo2<- ggplot(EC_Cran_Cher_hypo2, aes(x=logchange_Cranberry,
y=logchange_Cherry, group=Fruit_s, colour=Fruit_s)) +
geom_point(size=1.5, position=pd, fill="white", alpha=0.6) +
labs(colour = "Population with \nthe highest fitness \non each selection fruit:") +
geom_point(size=2, shape=21, fill="white", stroke = 2) +
scale_color_manual(values=c("#BC3C6D", "#FDB424","#3FAA96"),
label=c("Cherry","Cranberry", "Strawberry")) +
theme_LO_sober +
theme(legend.title = element_text(colour="black", size=10, face="bold"),
legend.text = element_text(colour="black", size=8))
extract_legend_hypo2<-lemon::g_legend(legend_hypo2)
ERRORCROSSES_G7_HYPO1 <- cowplot::ggdraw() +
cowplot::draw_plot(PAIR_CheCran_G29_HYPO_1+theme(legend.position = "none"),
x =0.00, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(PAIR_CranStraw_G29_HYPO_1+theme(legend.position = "none"),
x = 0.26, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(PAIR_StrawChe_G29_HYPO_1+theme(legend.position = "none"),
x = 0.52, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(legend_tradevide, x = 0.8, y = 0.73, width = 0.11, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo1, x = 0.83, y = 0.25, width = 0.1, height = 0.1)
ERRORCROSSES_G7_HYPO1
ERRORCROSSES_G7_HYPO2 <- cowplot::ggdraw() +
cowplot::draw_plot(PAIR_CheCran_G29_HYPO_2+theme(legend.position = "none"),
x =0.00, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(PAIR_CranStraw_G29_HYPO_2+theme(legend.position = "none"),
x = 0.26, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(PAIR_StrawChe_G29_HYPO_2+theme(legend.position = "none"),
x = 0.52, y = 0, width = 0.25, height = 1) +
cowplot::draw_plot(legend_tradevide, x = 0.78, y = 0.73, width = 0.1, height = 0.1) +
cowplot::draw_plot(extract_legend_hypo2, x = 0.82, y = 0.25, width = 0.1, height = 0.1)
ERRORCROSSES_G7_HYPO2
#
# cowplot::save_plot(file =here::here("figures", "SUPMAT_Pool_Hypothesis1.pdf"),
# ERRORCROSSES_G7_HYPO1,
# base_height = 7/cm(1), base_width = 28/cm(1), dpi = 610)
#
#
# cowplot::save_plot(file =here::here("figures", "SUPMAT_Pool_Hypothesis2.pdf"),
# ERRORCROSSES_G7_HYPO2,
# base_height = 7/cm(1), base_width = 28/cm(1), dpi = 610)